Python package to generate an httpx-based client off an OpenAPI spec
Project description
python-client-generator
Python package to generate an httpx- and pydantic-based async (or sync) client off an OpenAPI spec >= 3.0 (partial specification support).
flowchart LR
generator["python-client-generator"]
app["REST API App"]
package["App HTTP client"]
app -- "OpenAPI JSON" --> generator
generator -- "Generates" --> package
:warning: Currently does not support OpenAPI 2.x (PRs for < 3.0 support are welcome).
:exclamation: Only partial OpenAPI specification support, if you encounter unsupported spec. please feel free to contribute to the project.
Using the generator
Install the package (see on PyPi):
pip install python-client-generator
Run:
python -m python_client_generator --open-api openapi.json --package-name foo_bar --project-name foo-bar --outdir clients
This will produce a Python package with the following structure:
clients
├── foo_bar
│ ├── __init__.py
│ ├── apis.py
│ ├── base_client.py
│ └── models.py
└── pyproject.toml
Using PATCH functions from the generator
When calling one of the generated update functions that uses an HTTP PATCH
method, you'll
probably want to pass the additional argument body_serializer_args={"exclude_unset": True}
. This
will ensure that only the fields that are set in the update object are sent to the API. Example:
await api_client.update_contact_v1_contacts__contact_id__patch(
body=patch_body,
contact_id=contact.id,
tenant=tenant,
body_serializer_args={"exclude_unset": True}
)
Contributing
Please refer to CONTRIBUTING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_client_generator-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f8e7f2568daf90d5acb057c90d2e1603da90ffd214c2663e172dcdc0bd013c9 |
|
MD5 | e88f24710269e4d4924f67be40007926 |
|
BLAKE2b-256 | 7b42721fbbaf728d6d83212be6752c05d22c8ed7db5024a3960c290347880e03 |
Hashes for python_client_generator-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4914a153d4af135eaa52cffb58798b8ec6042a32ec8741644d0a596b9c278382 |
|
MD5 | 3f0b653102e49938e58342132833c661 |
|
BLAKE2b-256 | aea9da10c2c06eedf3d7587addfafac2a80271a78945f8da3b30bf6ecaa957bb |