openapi-py-fetch
Lightweight Python OpenAPI 3.x → Python httpx client generator and runtime. Zero Java, zero npm — just Python 3.11+ and your OpenAPI spec.
A fast, single-package alternative to the 200MB+ Java openapi-generator-cli.
Generates typed Python API classes backed by a shared httpx runtime.
Features
- OpenAPI 2.0 & 3.x — handles Swagger and OpenAPI specs
- Shared runtime —
ApiClient,Configuration, and exceptions are a pip-installable library, not duplicated per project - Thin generated output — only API classes are generated; they
import from openapi_py_fetch - No runtime duplication — unlike template-copy generators, the transport layer is maintained in one place
- Drop-in compatible — generated
openapi_clientpackage structure matches openapi-generator output - Typed models —
$ref,allOf,oneOf/anyOf, enums and nullable types resolve into TypedDicts, so responses and request bodies carry real types instead ofobject
Installation
pip install openapi-py-fetch
Usage
As a CLI
# Generate client from local spec
openapi-py-fetch openapi.json ./generated_openapi
# Generate from URL
openapi-py-fetch https://petstore.swagger.io/v2/swagger.json ./generated_openapi
# Generate only specific tags
openapi-py-fetch openapi.json ./generated_openapi --tags pet,store
# Dry run — validate and preview without writing files
openapi-py-fetch openapi.json --dry-run
# Check version
openapi-py-fetch --version
As a library (runtime)
from openapi_py_fetch import ApiClient, Configuration, ApiException
config = Configuration(
host="https://petstore.swagger.io/v2",
api_key={"api_key": "special-key"},
)
client = ApiClient(configuration=config)
As a library (generator)
from openapi_py_fetch.generator import generate_client_package
from pathlib import Path
import json
with open("openapi.json") as f:
spec = json.load(f)
generate_client_package(spec, Path("generated_openapi"))
Generated Output Structure
generated_openapi/
├── pyproject.toml # depends on openapi-py-fetch
└── openapi_client/
├── __init__.py # re-exports runtime + API classes
├── api/
│ ├── __init__.py
│ ├── pet_api.py # thin typed wrapper
│ ├── store_api.py
│ └── user_api.py
└── models/
└── __init__.py # TypedDict per schema
Typed Models
Object schemas become TypedDicts, collected in one models module:
class Pet(TypedDict):
"""A pet."""
id: str
name: NotRequired[str]
status: NotRequired[Literal["available", "pending", "sold"]]
TypedDict is the shape that matches what the runtime returns: ApiClient.call_api
hands back parsed JSON, so the annotation describes the dict a caller actually
receives, with no deserialization step and no runtime cost. A type checker still
catches a misspelled key or a wrong field type, and get_type_hints() resolves
every annotation for callers that introspect the generated client.
Resolved from the spec: $ref (including chains and self-references), allOf
(merged, with required fields propagated), oneOf and anyOf (unions), enums
(Literal), OpenAPI 3.1 nullable type arrays, additionalProperties, and
format: binary (bytes). Inline object schemas are named after their title
when they have one, otherwise after the operation they belong to.
Schema resolution is public API, for tools that read a spec rather than generate from it:
from openapi_py_fetch import SchemaRegistry
registry = SchemaRegistry(spec)
registry.python_type({"$ref": "#/components/schemas/Pet"}) # -> "Pet"
registry.models # -> {"Pet": {...}}
Comparison with openapi-ts-fetch
| openapi-py-fetch | openapi-ts-fetch | |
|---|---|---|
| Language | Python 3.11+ | TypeScript |
| HTTP transport | httpx | fetch |
| Runtime | Shared pip package | Copied template file |
| Generated output | Python classes | TypeScript classes |
| Models | TypedDicts | Interfaces + JSON converters |
| Response types | Resolved from the spec | Resolved from the spec |
License
MIT — Max Health Inc.
Release files for openapi-py-fetch 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openapi_py_fetch-0.3.0.tar.gz | 71.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openapi_py_fetch-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.0 kB
Release files / openapi_py_fetch-0.3.0.tar.gz
| Download URL | openapi_py_fetch-0.3.0.tar.gz |
|---|---|
| Size | 71.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c9c0c16817e64bc182145aca5d470435d232f3bf047bc266a85b750f71cad90
|
|
BLAKE2b-256 checksum How to use checksums |
b020c33d054e68b595d24456cb1c37d1ff65ee991cfeda3d6173cb725de1fdec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / openapi_py_fetch-0.3.0-py3-none-any.whl
| Download URL | openapi_py_fetch-0.3.0-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b606fa953e75aa1833d05bcc81a9cac25582539d6ae4610ed1771d4dbeef8a9
|
|
BLAKE2b-256 checksum How to use checksums |
a877d09788cf68972861f65f2707c2ac050fefa5c4c323da578c16b664a9b20d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency log