The Python package
A package for Python 3.11 or newer, with one dependency, httpx. It has a sync and an async client, and type hints throughout.
Its files
| File | What it holds |
|---|---|
pyproject.toml | The name, version, requires-python = ">=3.11", the httpx dependency, and pyright in strict mode. |
src/<module>/_client.py | The sync and async clients. |
src/<module>/resources/ | The operations, grouped by tag, a method each. |
src/<module>/types.py | A TypedDict for each schema. |
src/<module>/_core.py | The runtime, the same file in every Python SDK we generate. |
src/<module>/py.typed | The marker that tells type checkers the package is typed. |
README.md, GENERATION.md, CHANGELOG.md, LICENSE | As in the TypeScript package. |
The code is laid out as ruff format lays it out, so ruff format --check passes, and it type-checks under pyright's strict mode.
Clients
The client is named from clientName, and its async twin has Async in front: Acme and AsyncAcme. Both take the same arguments. Credentials are passed in, never read from the environment. Pass http_client= to use your own httpx.Client, and close a client with close(), aclose() for the async one, or a with block.
Retries, errors and responses
- Connection errors, timeouts,
408,429and5xxare retried with backoff, andRetry-Afteris honoured.POSTandPATCHare retried only with an idempotency key:idempotency_key=on a call, or one made for you when the operation declares anIdempotency-Keyheader. Setmax_retriesandtimeouton the client or per call. - A response outside
2xxraises anAPIErrorwithstatus_code,headers,bodyandrequest_id, as the same classes the TypeScript package throws. A network failure raisesAPIConnectionError, a timeoutAPITimeoutError. - Methods return the parsed JSON body, typed by the
TypedDicts. Every method has a…_with_responsesibling that returns(data, response), thehttpx.Response.
Where this comes from
app/sdk/_lib/python/emit.tsapp/sdk/_lib/python/types.tsapp/sdk/_lib/python/layout.tsapp/sdk/_lib/python/runtime/_core.pytests/fixtures/sdk/petstore/expected-python/README.md