Apigen is a small OpenAPI-to-Python client generator. It reads an OpenAPI 3 JSON spec, builds an intermediate representation, and emits a typed Python client using only the Python standard library.
The generated client includes dataclasses for schemas, endpoint methods, path/query parameters, JSON request bodies, bearer token and API-key hooks, plus a small ApiError wrapper.
- OpenAPI 3 JSON loader.
- Deterministic IR for models and operations.
- Python dataclass model generation.
- Endpoint methods from
operationId. - Path and query parameter support.
- JSON request/response mapping.
- Bearer token and
X-API-Keyauth hooks. - Golden tests for generated output.
- Integration test that runs the generated client against a local sample server.
go test ./...
go run ./cmd/apigen generate --spec examples/tiny-store.openapi.json --out client.py
python3 -m py_compile client.pyInspect a spec:
go run ./cmd/apigen inspect --spec examples/tiny-store.openapi.jsonapigen generate --spec openapi.json --out client.py
apigen inspect --spec openapi.json
apigen version
from client import Client, CreateUserRequest
client = Client("http://127.0.0.1:8080", bearer_token="dev-token")
users = client.list_users(limit=10)
created = client.create_user(CreateUserRequest(email="bob@example.test", display_name="Bob"))
print(users[0].email)
print(created.id)Generate the client:
go run ./cmd/apigen generate --spec examples/tiny-store.openapi.json --out examples/client.pyRun the sample server:
python3 examples/sample_server.pyIn another terminal:
PYTHONPATH=examples python3 examples/smoke_client.pyOn Windows with Python Launcher:
py -3 examples\sample_server.py
$env:PYTHONPATH = "examples"
py -3 examples\smoke_client.pyThis MVP intentionally supports a focused subset:
- JSON OpenAPI specs
components.schemas- object schemas, primitive fields, arrays and
$ref - JSON request bodies
- JSON 2xx responses
- path and query parameters
It does not store secrets in generated clients. Tokens are passed at runtime via Client(..., bearer_token=...) or api_key=....
flowchart LR
A["OpenAPI JSON"] --> B["schema loader"]
B --> C["intermediate representation"]
C --> D["Python backend"]
D --> E["client.py"]
E --> F["golden + integration tests"]
More details are in docs/architecture.md.
MIT