Skip to content

Commit 6434eb3

Browse files
chrisdengsogithub-actions[bot]
authored andcommitted
feat: regenerate from the OpenAPI spec
1 parent 88df073 commit 6434eb3

395 files changed

Lines changed: 9205 additions & 10422 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/release-notes/v2.0.0.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## moderation_api 2.0.0
2+
3+
A new major version of the Python SDK. Read the breaking changes before you upgrade.
4+
5+
```bash
6+
pip install --upgrade "moderation_api>=2,<3"
7+
```
8+
9+
### Python-specific changes
10+
11+
- Requires Python 3.10 or later (was 3.9).
12+
- Use the client as a context manager: `with ModerationAPI() as client:`. Every method has an `_async` version, for example `await client.content.submit_async(...)`.
13+
- Methods take keyword arguments in snake_case, for example `client.content.submit(content={...}, author_id="user-123")`.
14+
- Verify webhooks with `moderation_api.webhook_signature.construct_event(payload, signature)`.
15+
### What's new
16+
17+
- **Covers the whole API**, including the management API (`projects`, `channels`), wordlists and the review queue.
18+
- **Automatic pagination.** List methods return an iterator that fetches the next page for you.
19+
- **Clear errors.** One error class per HTTP status (`BadRequestError`, `NotFoundError`, `RateLimitError`, ...). Every error has a specific `code` (for example `invalid_api_key`, `quota_exceeded` or `author_not_found`), a `request_id` and a `doc_url`. See [Errors](https://docs.moderationapi.com/api-reference/errors).
20+
- **Retries** with exponential backoff on `429` and `5xx`, and timeouts per client or per request.
21+
- **Webhook verification** that reads the secret from `MODAPI_WEBHOOK_SECRET`.
22+
23+
### Breaking changes
24+
25+
The SDK is now generated from our OpenAPI spec with a new generator. Most calls keep their names, but check these:
26+
27+
- **List responses** are `{ data, pagination }` instead of a plain array or a resource-specific shape, and list methods take `page` and `pageSize`.
28+
- **Errors** have a new body: `code` is the specific error code, not the HTTP category. The old `data` field is gone.
29+
- **Renamed:** `account.list` is now `account.retrieve`, and `actions.execute.execute` is now `actions.execute`.
30+
- **Removed:** `actions.execute.executeByID` (use `actions.execute` with `actionId` or `actionKey`), `auth.*`, and `content.stream` (see [Real-time voice](https://docs.moderationapi.com/content-moderation/real-time-voice)).
31+
- **Organization keys** work only with `projects` and `channels`; project keys work with everything else. Use one client per key. See the README.
32+
33+
The license is unchanged: Apache-2.0.

‎.github/workflows/publish-pypi.yml‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
11
# Maintained in moderation-api/sdk-generator (custom/python). Edits here are overwritten.
2+
# Every push to main whose package version has no release tag yet publishes
3+
# that version and creates the GitHub release (notes: .github/release-notes/vX.Y.Z.md
4+
# if present, otherwise generated from the merged pull requests).
25
name: Publish PyPI
36
on:
4-
release:
5-
types: [published]
7+
push:
8+
branches: [main]
69
workflow_dispatch:
710

11+
concurrency: release
12+
813
permissions:
9-
contents: read
14+
contents: write
1015

1116
jobs:
1217
publish:
1318
runs-on: ubuntu-latest
1419
steps:
1520
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
- name: Read the version
22+
run: echo "VERSION=$(sed -n 's/^version = \"\(.*\)\"$/\1/p' pyproject.toml | head -n 1)" >> "$GITHUB_ENV"
23+
- name: Check for an unreleased version
24+
id: version
25+
run: |
26+
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
27+
if git ls-remote --exit-code --tags origin "refs/tags/v${VERSION}" >/dev/null; then
28+
echo "v${VERSION} is already released."
29+
echo "release=false" >> "$GITHUB_OUTPUT"
30+
else
31+
echo "release=true" >> "$GITHUB_OUTPUT"
32+
fi
1633
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
34+
if: steps.version.outputs.release == 'true'
1735
with:
1836
version: "0.9.13"
19-
- name: Check the release tag matches pyproject.toml
20-
if: github.event_name == 'release'
21-
run: |
22-
version=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -1)
23-
if [ "${GITHUB_REF_NAME#v}" != "$version" ]; then
24-
echo "::error::Release tag $GITHUB_REF_NAME does not match pyproject.toml version $version"
25-
exit 1
26-
fi
27-
- run: bash scripts/publish.sh
37+
- if: steps.version.outputs.release == 'true'
38+
run: bash scripts/publish.sh
2839
env:
2940
PYPI_TOKEN: ${{ secrets.MODERATION_API_PYPI_TOKEN || secrets.PYPI_TOKEN }}
41+
- name: Create the GitHub release
42+
if: steps.version.outputs.release == 'true'
43+
env:
44+
GH_TOKEN: ${{ github.token }}
45+
run: |
46+
notes=".github/release-notes/v${VERSION}.md"
47+
if [ -f "$notes" ]; then
48+
gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --notes-file "$notes"
49+
else
50+
gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --generate-notes
51+
fi

0 commit comments

Comments
 (0)