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.
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.0: PR for < 3.0 support are welcome
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
Hashes for python_client_generator-1.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22d664d47a70e771a6045e627cbdfcce234374179b7e7d0dce913cbf9bb72e70 |
|
MD5 | cc9d9e900ac61685eae5deb14520a59c |
|
BLAKE2b-256 | 0278ab53d915dcd5a6ea73a76cf8e8336864d73beaa714d81cd8a829850211db |
Hashes for python_client_generator-1.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6e14420d557c6d28d1ffcc2497cb821ba746b054700e862207c039f9e3e3a51 |
|
MD5 | d27ed2b37b1d467c68e605527a991dfb |
|
BLAKE2b-256 | acd17a173c31ca3ffbc159c947e7102cbe0cd6d8055f58f1a20827daeea0e8b4 |