feat(sdk): add Python SDK with auto-regen CI by nbilbeny · Pull Request #24968 · anomalyco/opencode · GitHub
Skip to content

feat(sdk): add Python SDK with auto-regen CI - #24968

Closed
nbilbeny wants to merge 3 commits into
anomalyco:devfrom
nbilbeny:feat/python-sdk
Closed

nbilbeny wants to merge 3 commits into
anomalyco:devfrom
nbilbeny:feat/python-sdk

Conversation

@nbilbeny

@nbilbeny nbilbeny commented Apr 29, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #4031.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Brings back a Python SDK at packages/sdk/python, generated from packages/sdk/openapi.json with openapi-python-client (the generator @thdxr asked for in #2266).

The last attempt got removed in 13b2cf5 because it had no regen CI. This one ships the SDK and the regen step together — python scripts/generate.py --check runs on every PR touching python or the spec, so the tree can't drift.

Hand-written bits are just __init__.py, server.py (mirrors createOpencodeServer in JS, sync + async), README, pyproject, CI. Everything else is regenerable from the spec via scripts/_overlay/ + scripts/generate.py.

How did you verify your code works?

Locally on Python 3.13 and Bun 1.3.13:

  • python scripts/generate.py --check — clean
  • ruff check + ruff format --check — clean
  • python -m build — wheel + sdist
  • pytest tests/ — 9 passed (5 unit + 4 smoke against a live opencode serve spawned from this checkout)

CI runs the same on 3.10 and 3.13.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Adds packages/sdk/python — a Python SDK generated from packages/sdk/openapi.json
using openapi-python-client, plus the hand-written surface and CI that keeps
it in sync with the same OpenAPI document the JS SDK is generated from.

Hand-written:
- pyproject.toml (hatchling, Python 3.10+, deps: httpx + attrs + python-dateutil)
- src/opencode_ai/__init__.py public exports
- src/opencode_ai/server.py — sync ServerHandle / async AsyncServerHandle
  helpers mirroring createOpencodeServer in packages/sdk/js
- README.md modeled on the JS SDK README
- scripts/_overlay/* — source of truth for files the generator does not produce
- scripts/generate.py — regenerate / --check used by CI
- tests/test_unit.py + tests/test_smoke.py
- examples/basic_usage.py

CI (.github/workflows/python-sdk.yml) runs lint, scripts/generate.py --check
(fails the build on openapi.json drift), pytest against a live opencode server
spawned from the local checkout, and a hatchling distribution build, on every
push/PR that touches packages/sdk/python or packages/sdk/openapi.json.

The previous Python SDK was removed in 13b2cf5 ("remove outdated SDKs") for
exactly this reason — without a sync CI, the generated tree drifts. This PR
ships the SDK and the regen CI together so it stays current.

Refs anomalyco#4031, anomalyco#2266.
Output of `python packages/sdk/python/scripts/generate.py` against the
current packages/sdk/openapi.json (98 paths, 168 schemas) using
openapi-python-client 0.28.x. Source of truth for these files is the OpenAPI
spec; do not edit by hand. CI runs the generator with --check on every PR.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Apr 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@nbilbeny nbilbeny changed the title _test_ feat(sdk): add Python SDK with auto-regen CI Apr 29, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@nbilbeny
nbilbeny marked this pull request as ready for review April 29, 2026 15:04
Two CI bugs caught before any maintainer review on PR anomalyco#24968:

- The job-level `defaults.run.working-directory: packages/sdk/python` would
  propagate into the `setup-bun` composite action, where its `node -p` and
  `bun install` steps must run from the repo root. Drop the default and
  scope `working-directory` per step instead, matching how `test.yml` and
  `typecheck.yml` invoke setup-bun.
- `openapi-python-client` and `ruff` were ranged dependencies. A patch
  release with even a one-line formatting change would cause
  `scripts/generate.py --check` to fail in CI weeks after merge. Pin both
  to the exact versions the committed tree was generated with
  (openapi-python-client 0.28.3, ruff 0.15.12). Bump alongside a regen
  commit when needed.
@github-actions

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK

1 participant