Python Client Generation#

Generate a typed Python client from your deployment’s /openapi.json.

openapi-python-client#

Generates a complete Python package with Pydantic models and an httpx-based client.

pip install openapi-python-client

# Generate client package
openapi-python-client generate \
  --url http://localhost:3000/openapi.json \
  --output-path ./api-client

Usage:

from api_client import Client
from api_client.api.default import hello_world

client = Client(base_url="http://localhost:3000")
response = hello_world.sync(client=client, name="World")
print(response.message)

# Async
response = await hello_world.asyncio(client=client, name="World")

Updating#

When handlers change, regenerate:

openapi-python-client update \
  --url http://localhost:3000/openapi.json \
  --output-path ./api-client

Alternative: openapi-generator#

openapi-generator generate \
  -i http://localhost:3000/openapi.json \
  -g python \
  -o ./api-client