Skip to content

Commit dd8df9d

Browse files
vernuclaude
andcommitted
feat: add the textbee Python SDK 0.1.0
A zero-dependency port of @textbee/sdk for Python 3.9 and later: send SMS, list and read messages, manage devices, verify webhook signatures, and the SMS segment and phone number helpers. Includes CI on Python 3.9 to 3.14 and a release workflow that publishes to PyPI through trusted publishing when __version__ changes on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0 parents  commit dd8df9d

21 files changed

Lines changed: 3865 additions & 0 deletions

‎.coderabbit.yaml‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
2+
3+
language: en-US
4+
5+
tone_instructions: >-
6+
Be direct and concise. Never use em dashes or en dashes in any comment,
7+
summary, or suggested code. Use periods, commas, colons, or parentheses.
8+
9+
reviews:
10+
profile: chill
11+
request_changes_workflow: false
12+
high_level_summary: true
13+
review_status: true
14+
poem: false
15+
16+
auto_review:
17+
enabled: true
18+
drafts: false
19+
ignore_title_keywords:
20+
- WIP
21+
- DO NOT MERGE
22+
23+
path_filters:
24+
- '!**/.DS_Store'
25+
- '!**/uv.lock'
26+
- '!dist/**'
27+
- '!.venv/**'
28+
29+
path_instructions:
30+
- path: '**'
31+
instructions: |
32+
Never use em dashes or en dashes anywhere, including code comments,
33+
docstrings, metadata, and commit messages. Use a period, comma, colon,
34+
parentheses, or a plain hyphen instead.
35+
This project uses uv only. Flag pip, poetry, or pipenv commands in
36+
scripts, CI, and contributor docs (the README install line for end
37+
users is fine).
38+
Keep functions small and single-purpose.
39+
Never run package installs or commit uv.lock changes when applying
40+
fixes. The lockfile changes only together with a pyproject.toml change.
41+
42+
- path: 'src/**/*.py'
43+
instructions: |
44+
This is a published SDK, so the exported surface is a contract. Flag
45+
breaking changes to exported names, method signatures, or return
46+
shapes, since fixing them later needs a major release.
47+
Flag any new runtime dependency. This package ships with zero and uses
48+
the standard library (urllib) for HTTP.
49+
The package supports Python 3.9. Flag syntax or stdlib APIs newer than
50+
3.9 outside annotations (annotations are deferred by
51+
`from __future__ import annotations`).
52+
Flag anything that could log or surface the api key or a webhook
53+
signing secret, including error messages, repr, and raised exceptions.
54+
Flag drift from the REST contract: auth is the x-api-key header and
55+
never a query param, request bodies use the modern field names
56+
(message, recipients) and never smsBody or receivers, and each endpoint
57+
has its own response envelope. get_messages returns {data, meta} with
58+
no outer wrapper and get_sms_batch nests under data, so a single
59+
generic unwrap is wrong.
60+
Keep parity with textbee-js (github.com/textbee/textbee-js): same
61+
operations, same base URL normalization, same SMS utility results.
62+
Python names are snake_case; response dict keys keep the API's
63+
camelCase wire names.
64+
Non-ASCII characters in string literals in _sms_utils.py must be
65+
written as escapes, so lookalike characters cannot sneak in.
66+
67+
- path: '.github/workflows/**'
68+
instructions: |
69+
Flag unpinned action versions, secrets echoed into logs or files, and
70+
steps that would run untrusted code from fork pull requests.
71+
72+
tools:
73+
# Waits for ALL GitHub Checks, then comments on failures.
74+
github-checks:
75+
enabled: true
76+
77+
chat:
78+
auto_reply: true
79+
# Public repo, so outside contributors can spend the chat quota.
80+
# Set to false if that becomes a problem.
81+
allow_non_org_members: true
82+
83+
knowledge_base:
84+
learnings:
85+
scope: auto
86+
issues:
87+
scope: auto
88+
pull_requests:
89+
scope: auto

‎.github/workflows/ci.yaml‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
# Superseded runs on the same branch or PR are cancelled.
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
lint:
24+
name: Lint and typecheck
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 10
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
31+
with:
32+
persist-credentials: false
33+
34+
- name: Set up uv
35+
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
36+
with:
37+
enable-cache: true
38+
39+
- name: Install dependencies
40+
run: uv sync --locked
41+
42+
- name: Lint
43+
run: uv run ruff check .
44+
45+
- name: Format
46+
run: uv run ruff format --check .
47+
48+
- name: Typecheck
49+
run: uv run mypy
50+
51+
test:
52+
name: Test on Python ${{ matrix.python-version }}
53+
runs-on: ubuntu-latest
54+
timeout-minutes: 10
55+
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
60+
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
64+
with:
65+
persist-credentials: false
66+
67+
- name: Set up uv
68+
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
69+
with:
70+
python-version: ${{ matrix.python-version }}
71+
enable-cache: true
72+
73+
- name: Install dependencies
74+
run: uv sync --locked
75+
76+
- name: Unit test
77+
run: uv run pytest
78+
79+
build:
80+
name: Build package
81+
runs-on: ubuntu-latest
82+
timeout-minutes: 10
83+
84+
steps:
85+
- name: Checkout repository
86+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
87+
with:
88+
persist-credentials: false
89+
90+
- name: Set up uv
91+
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
92+
with:
93+
enable-cache: true
94+
95+
- name: Build sdist and wheel
96+
run: uv build
97+
98+
# Installs the built wheel alone, outside the project, so a file missing
99+
# from the package fails here instead of on PyPI.
100+
- name: Import the built wheel
101+
run: uv run --isolated --no-project --with dist/*.whl python -c "import textbee; print(textbee.__version__)"

‎.github/workflows/release.yaml‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Releasing is driven by __version__ in src/textbee/_version.py.
2+
#
3+
# Bump it, merge it to main, and this publishes it. The pull request carrying
4+
# the bump is the release proposal: reviewing and merging it is the approval
5+
# step, so there is no bot pull request on top of it.
6+
#
7+
# The guard compares the version against the git tags, not against the
8+
# previous commit, so the job is idempotent. Pushes that do not change the
9+
# version are a no-op, and a failed release can be retried by pushing again.
10+
#
11+
# Jobs are split by privilege. Only the publish job can mint a PyPI token, and
12+
# it runs nothing but the publish action. Actions are pinned to commit SHAs.
13+
name: Release
14+
15+
on:
16+
push:
17+
branches:
18+
- main
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
# Never let two releases run at once, and never cancel one midway: an
25+
# interrupted run can leave a version on PyPI with no tag behind it.
26+
concurrency:
27+
group: release
28+
cancel-in-progress: false
29+
30+
jobs:
31+
check:
32+
name: Check for an unreleased version
33+
# A dispatch from any other branch must never publish.
34+
if: github.ref == 'refs/heads/main'
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 5
37+
outputs:
38+
version: ${{ steps.check.outputs.version }}
39+
should_release: ${{ steps.check.outputs.should_release }}
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
44+
with:
45+
# Tags are the record of what has shipped, so fetch all of them.
46+
fetch-depth: 0
47+
persist-credentials: false
48+
49+
- name: Compare the package version against existing tags
50+
id: check
51+
run: |
52+
version="$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/textbee/_version.py)"
53+
if [ -z "$version" ]; then
54+
echo "Could not read __version__ from src/textbee/_version.py" >&2
55+
exit 1
56+
fi
57+
echo "version=$version" >> "$GITHUB_OUTPUT"
58+
59+
if git rev-parse "v$version" >/dev/null 2>&1; then
60+
echo "should_release=false" >> "$GITHUB_OUTPUT"
61+
echo "v$version is already tagged, nothing to release."
62+
else
63+
echo "should_release=true" >> "$GITHUB_OUTPUT"
64+
echo "v$version has no tag yet, releasing."
65+
fi
66+
67+
build:
68+
name: Build v${{ needs.check.outputs.version }}
69+
needs: check
70+
if: needs.check.outputs.should_release == 'true'
71+
runs-on: ubuntu-latest
72+
timeout-minutes: 15
73+
74+
steps:
75+
- name: Checkout repository
76+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
77+
with:
78+
persist-credentials: false
79+
80+
# No cache: a release builds from a clean slate.
81+
- name: Set up uv
82+
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
83+
with:
84+
enable-cache: false
85+
86+
- name: Install dependencies
87+
run: uv sync --locked
88+
89+
- name: Lint
90+
run: uv run ruff check .
91+
92+
- name: Typecheck
93+
run: uv run mypy
94+
95+
- name: Unit test
96+
run: uv run pytest
97+
98+
# The oldest supported Python, so a 3.9-only break cannot publish.
99+
- name: Unit test on Python 3.9
100+
run: uv run --isolated --python 3.9 --group dev pytest
101+
102+
- name: Build sdist and wheel
103+
run: uv build
104+
105+
- name: Upload distributions
106+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
107+
with:
108+
name: dist
109+
path: dist/
110+
if-no-files-found: error
111+
112+
publish:
113+
name: Publish v${{ needs.check.outputs.version }} to PyPI
114+
needs: [check, build]
115+
runs-on: ubuntu-latest
116+
timeout-minutes: 10
117+
# Must match the environment named in the PyPI trusted publisher.
118+
environment:
119+
name: pypi
120+
url: https://pypi.org/project/textbee/${{ needs.check.outputs.version }}/
121+
permissions:
122+
# Minting the OIDC token PyPI exchanges for a publish credential.
123+
id-token: write
124+
125+
steps:
126+
- name: Download distributions
127+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
128+
with:
129+
name: dist
130+
path: dist/
131+
132+
# PyPI publish runs before tagging on purpose. If it fails there is no
133+
# tag, so the next push retries cleanly. skip-existing lets that retry
134+
# move on to tagging when an earlier run already uploaded the files.
135+
#
136+
# No token: the OIDC exchange authenticates this publish, and the action
137+
# attaches PEP 740 attestations automatically.
138+
- name: Publish to PyPI
139+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
140+
with:
141+
skip-existing: true
142+
143+
github-release:
144+
name: Tag and release v${{ needs.check.outputs.version }}
145+
needs: [check, publish]
146+
runs-on: ubuntu-latest
147+
timeout-minutes: 5
148+
permissions:
149+
# Creating the tag and the GitHub release.
150+
contents: write
151+
152+
steps:
153+
- name: Download distributions
154+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
155+
with:
156+
name: dist
157+
path: dist/
158+
159+
# Creates the tag as well as the release. Notes are generated from the
160+
# commits since the previous tag.
161+
- name: Create GitHub release
162+
env:
163+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
GH_REPO: ${{ github.repository }}
165+
VERSION: ${{ needs.check.outputs.version }}
166+
run: |
167+
gh release create "v$VERSION" \
168+
--title "v$VERSION" \
169+
--target "$GITHUB_SHA" \
170+
--generate-notes \
171+
dist/*

‎.gitignore‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__pycache__/
2+
*.py[cod]
3+
.venv/
4+
dist/
5+
build/
6+
*.egg-info/
7+
.pytest_cache/
8+
.mypy_cache/
9+
.ruff_cache/
10+
.coverage
11+
htmlcov/
12+
.DS_Store
13+
.omc/

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 - 2026 textbee.dev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)