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.
flowchart LR
generator["python-client-generator"]
app["REST API app"]
package["app HTTP client"]
app -- "OpenAPI json" --> generator
generator -- "generates" --> package
Using the generator
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
Close
Hashes for python-client-generator-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b49e040ee4979e32fcbe9623af39526eb036548ff76e00e1067b3eceb6f0b174 |
|
MD5 | 8a16d50ea8e4008fb0ace113f0572227 |
|
BLAKE2b-256 | 9ad8c01238ad6edd2b248c32d6f2c82e3177cbc799b02cc93359a52a30434e3e |
Close
Hashes for python_client_generator-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8957a59496a734c8d8f78c888234de7200f5438020e874c23d7f09088fbfc8 |
|
MD5 | 6b647e92acc6cf7fff8c28314507cbb4 |
|
BLAKE2b-256 | 71d31e8702bc6dd3cb10633d4ac66ba9a4df90305d3b3098e4a3ba9cb8cde542 |