Skip to content

Commit 711c109

Browse files
captainyugi00claude
andcommitted
Implement async Threads Python SDK
Full-featured async SDK for the Meta Threads API built on aiohttp and Pydantic v2, following the same architecture as the TikTok Python SDK. Six API namespaces: user profiles, content publishing (text/image/video/ carousel with container polling), media retrieval with auto-pagination, insights/analytics with demographic breakdowns, reply management, and keyword search. Includes typed exception hierarchy, 41 tests with aioresponses mocking, ruff + mypy strict CI, and release workflow with PyPI trusted publishing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 25c1100 commit 711c109

35 files changed

Lines changed: 2973 additions & 1 deletion

.github/workflows/ci.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main", "develop"]
6+
pull_request:
7+
branches: ["main", "develop"]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
name: Lint & format check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
25+
- name: Install ruff
26+
run: pip install ruff
27+
28+
- name: Check formatting
29+
run: ruff format --check .
30+
31+
- name: Lint
32+
run: ruff check .
33+
34+
type-check:
35+
name: Type check (mypy)
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.12"
44+
45+
- name: Install dependencies
46+
run: pip install -e ".[dev]"
47+
48+
- name: Run mypy
49+
run: mypy threads/
50+
51+
test:
52+
name: Tests (Python ${{ matrix.python-version }})
53+
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
python-version: ["3.11", "3.12", "3.13"]
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Set up Python ${{ matrix.python-version }}
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
67+
- name: Cache pip
68+
uses: actions/cache@v4
69+
with:
70+
path: ~/.cache/pip
71+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
72+
restore-keys: |
73+
${{ runner.os }}-pip-${{ matrix.python-version }}-
74+
75+
- name: Install dependencies
76+
run: pip install -e ".[dev]"
77+
78+
- name: Run tests with coverage
79+
run: |
80+
pip install pytest-cov
81+
pytest --cov=threads --cov-report=xml --cov-report=term-missing
82+
83+
- name: Upload coverage to Codecov
84+
if: matrix.python-version == '3.12'
85+
uses: codecov/codecov-action@v4
86+
with:
87+
files: coverage.xml
88+
fail_ci_if_error: false

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
permissions:
9+
contents: write
10+
id-token: write
11+
12+
jobs:
13+
validate:
14+
name: Validate tag matches package version
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Install package
25+
run: pip install -e .
26+
27+
- name: Check version match
28+
run: |
29+
TAG_VERSION="${GITHUB_REF_NAME#v}"
30+
PKG_VERSION=$(python -c "import threads; print(threads.__version__)")
31+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
32+
echo "Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)."
33+
exit 1
34+
fi
35+
echo "Version check passed: $PKG_VERSION"
36+
37+
test:
38+
name: Full test suite before release
39+
needs: validate
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
python-version: ["3.11", "3.12", "3.13"]
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Set up Python ${{ matrix.python-version }}
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: ${{ matrix.python-version }}
51+
52+
- name: Install dependencies
53+
run: pip install -e ".[dev]"
54+
55+
- name: Run tests
56+
run: pytest
57+
58+
build-and-publish:
59+
name: Build distribution and publish to PyPI
60+
needs: test
61+
runs-on: ubuntu-latest
62+
environment:
63+
name: pypi
64+
url: https://pypi.org/project/threads-python-sdk/
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Set up Python
69+
uses: actions/setup-python@v5
70+
with:
71+
python-version: "3.12"
72+
73+
- name: Install build tools
74+
run: pip install hatch
75+
76+
- name: Build distributions
77+
run: hatch build
78+
79+
- name: Publish to PyPI
80+
uses: pypa/gh-action-pypi-publish@release/v1
81+
82+
github-release:
83+
name: Create GitHub release
84+
needs: build-and-publish
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v4
88+
with:
89+
fetch-depth: 0
90+
91+
- name: Create GitHub Release
92+
uses: softprops/action-gh-release@v2
93+
with:
94+
generate_release_notes: true
95+
draft: false
96+
prerelease: ${{ contains(github.ref_name, '-') }}

0 commit comments

Comments
 (0)