Python Client Generation#
Scope: advanced template API surface. This guide consumes REST/RPC endpoints generated by the advanced template — it is not a client for the pgmi deployment CLI.
Generate a typed Python client from your deployment’s /openapi.json. Download openapi.json with session handles first; see Client generation
.
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 \
--path openapi.json \
--output-path ./api-clientUsage:
from api_client import Client
from api_client.api.default import hello_world
client = Client(
base_url="http://localhost:8080/api",
headers={"Cookie": f"__Host-session={login_session}; __Host-csrf={csrf_token}",
"X-CSRF-Token": csrf_token, "x-organization-session": organization_session},
)
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, download the spec again and regenerate:
openapi-python-client generate --overwrite \
--path openapi.json \
--output-path ./api-clientAlternative: openapi-generator#
openapi-generator generate \
-i openapi.json \
-g python \
-o ./api-client