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
Install the dependencies with poetry
:
poetry install
Format the code:
make format
Test the code locally:
poetry run pytest
Commiting
We use commitlint in the CI/CD to make sure all commit messages adhere to conventionalcommits. See .commitlintrc.js
, .releaserc
and .czrc.json
for specific implementation details.
As per the default commitlint settings for conventionalcommits (see here) the following commit types may be used:
build
chore
ci
docs
feat
fix
perf
refactor
revert
style
test
Of which the following will cause a release (one of these types must be used if you are submitting code that you expect to be deployed after merging):
build
ci
docs(api)
feat
fix
perf
refactor
revert
To ensure that your commits always conform to the above format, you can install commitizen
:
npm i -g commitizen
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.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bdd10916755b40927e3c726ed1d43e198062dcf58799eca6ca9f08e11671a77 |
|
MD5 | 5aebc219c084addb4cfd23f0c8b10b14 |
|
BLAKE2b-256 | a63651b5ecf9e328c1139aebbd3bc8c4b05ff8a968c7b8871dd481edbf40b9b6 |
Hashes for python_client_generator-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac55c7c967f0ce091119ce8d966e9bb9d9905969b9a6e79ba8ab9bd794193ee6 |
|
MD5 | 491edfa994c27444834003e061a2d734 |
|
BLAKE2b-256 | 193375ce38853f786b1911a1c9ab3ffbf41a7db0b6c876261158508e70aa8f92 |