big format

This commit is contained in:
Dax Raad
2025-11-06 13:03:02 -05:00
parent 8729edc5e0
commit 1ea3a8eb9b
183 changed files with 2629 additions and 2497 deletions

View File

@@ -2,50 +2,59 @@
This package provides a Python SDK for the Opencode API. It is generated using openapi-python-client (not Stainless).
Documentation
- Full docs: see `mkdocs` site under `packages/sdk/python/docs/`
- Preview locally:
```bash
uv run --project packages/sdk/python mkdocs serve -f packages/sdk/python/mkdocs.yml
```
Badges
- PyPI: https://img.shields.io/pypi/v/opencode-ai?style=flat-square
Requirements
- Python 3.8+
- uv (recommended) -> https://docs.astral.sh/uv/
- openapi-python-client (invoked via `uvx`)
Install uv
```bash
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
```
Set up the environment (from this directory)
```bash
uv sync --dev
```
Generate client code (from CLI-generated spec)
```bash
# From repository root OR from this directory
uv run python packages/sdk/python/scripts/generate.py --source cli
```
Alternatively, fetch spec from a running server
```bash
uv run python packages/sdk/python/scripts/generate.py --source server --server-url http://localhost:4096/doc
```
This will:
1) Produce an OpenAPI spec from the local CLI or a running server
2) Run openapi-python-client (via `uvx`) to generate client code
3) Copy the generated Python package into src/opencode_ai
1. Produce an OpenAPI spec from the local CLI or a running server
2. Run openapi-python-client (via `uvx`) to generate client code
3. Copy the generated Python package into src/opencode_ai
Usage (after generation)
```python
from opencode_ai import OpenCodeClient
@@ -77,6 +86,7 @@ client = OpenCodeClient(retries=2, backoff_factor=0.1)
```
Notes
- We intentionally do not use Stainless for the Python SDK.
- The generator targets OpenAPI 3.1 emitted by the opencode server at /doc.
- See scripts/generate.py for details and customization points.

View File

@@ -3,10 +3,12 @@
The SDK is generated from the Opencode server's OpenAPI 3.1 spec.
Two source modes are supported:
- CLI (default): runs `bun dev generate` to emit the OpenAPI JSON
- Server: fetches `http://localhost:4096/doc` from a running server
Generator command
```bash
# From repo root
uv run --project packages/sdk/python python packages/sdk/python/scripts/generate.py --source cli
@@ -15,5 +17,6 @@ uv run --project packages/sdk/python python packages/sdk/python/scripts/generate
```
Post-generation
- The generator injects `extras.py` (OpenCodeClient) and patches `__init__.py` to export it
- Code is formatted with `ruff` (imports) and `black`

View File

@@ -3,6 +3,7 @@
The official Python client for the Opencode API, generated from the OpenAPI spec and extended with ergonomic helpers.
Highlights
- Provider-agnostic client generated from OpenAPI 3.1
- Thin convenience wrapper (OpenCodeClient) for common tasks
- Sync and async SSE streaming for live event feeds

View File

@@ -1,26 +1,31 @@
# Installation
Requirements
- Python 3.8+
- uv (recommended) -> https://docs.astral.sh/uv/
Install uv
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```
Project setup
```bash
# From repo root or this directory
uv sync --dev --project packages/sdk/python
```
Using pip (alternative)
```bash
pip install opencode-ai
```
Preview docs locally
```bash
# From repo root
uv run --project packages/sdk/python mkdocs serve -f packages/sdk/python/mkdocs.yml

View File

@@ -3,6 +3,7 @@
Automated publishing runs on GitHub Releases.
Workflow
- Create a new Release (the tag value becomes the package version)
- The `publish-python-sdk` workflow will:
- Generate the SDK from OpenAPI (CLI path)
@@ -10,9 +11,11 @@ Workflow
- Build wheel/sdist and upload to PyPI
Prerequisites
- Repository secret: `PYPI_API_TOKEN`
Manual publish
```bash
# TestPyPI
REPOSITORY=testpypi PYPI_TOKEN=$TEST_PYPI_API_TOKEN \

View File

@@ -11,5 +11,6 @@ uv run --project packages/sdk/python pytest -q
```
Notes
- Integration test starts a headless opencode server via Bun in a subprocess
- SSE behavior is validated using real streaming from the server

View File

@@ -3,7 +3,7 @@ site_description: Official Python SDK for the Opencode API
site_url: https://opencode.ai
repo_url: https://github.com/sst/opencode
repo_name: sst/opencode
edit_uri: ''
edit_uri: ""
theme:
name: material
features: