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.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38e89b54df3f43cfb6ab59698486276e5ccf07aff9eb696272d858828668564a |
|
MD5 | 6be458f9caf524e74da35feb2cc8ea38 |
|
BLAKE2b-256 | 63e1c9c536c5c4863e5e59b423fcba5229af7a821737c91a9f924f2cec36bab2 |
Hashes for python_client_generator-1.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2009abea0c66bd1fbd22bc963eb78cf1d0448d42b73f0ac377099e64db27737f |
|
MD5 | bb3a403f2f7f4bc5e7811b4d3b7047c6 |
|
BLAKE2b-256 | 6d03ced4f8105d5397d1e98941a86b147e1d79f0b377004788b327a4216bcf6e |