OpenAPI HTTPX
Generate a typed HTTPX client from an OpenAPI specification. Provides an extremely thin wrapper around the HTTPX Client class that registers overloads for each operation and defines TypedDicts for parameters, request bodies and response bodies.
Installation
pip install openapi-httpx
# or
uv add openapi-httpx
# or
poetry add openapi-httpx
The generated client code imports httpx at runtime. Make sure to install it in any environment where you run the generated client:
pip install httpx
(or uv add httpx / poetry add httpx)
Usage
openapi-httpx --input <OpenAPI yaml/json/url> --output client.py
This produces a client class with overloads for each operation:
class GetUserByIdParams(TypedDict):
id: str
class User(TypedDict):
id: str
name: str
email: str
class PostFileUploadRequest(TypedDict):
name: str
description: str
class OpenApiClient(Client):
@overload
def GET(
self,
path: Literal["/user/{id}"],
*,
params: GetUserByIdParams,
parse_as: Literal["json"] = "json",
**kwargs: Unpack[RequestKwargs]
) -> User:
"""Get a user by ID"""
pass
@overload
def POST(
self,
path: Literal["/user"],
*,
params: None = None,
json: User,
data: None = None,
content: None = None,
files: None = None,
parse_as: Literal["json"] = "json",
**kwargs: Unpack[RequestKwargs]
) -> User:
"""Create a user"""
pass
@overload
def POST(
self,
path: Literal["/file"],
*,
params: None = None,
json: None = None,
data: PostFileUploadRequest,
files: dict[Literal["file"], FileTypes] | list[tuple[Literal["file"], FileTypes]],
content: None = None,
parse_as: Literal["json"] = "json",
**kwargs: Unpack[RequestKwargs]
) -> None:
"""Upload a file"""
pass
CLI Options
| Flag | Description |
|---|---|
--input |
OpenAPI specification file path or URL (required) |
--output |
Output file path (required) |
--target-python-version |
Target Python version (default: 3.11) |
--client-class-name |
Name of the generated client class (default: OpenApiClient) |
--async-client |
Generate an async client based on httpx.AsyncClient |
--use-closed-typed-dict |
Generate closed TypedDicts (PEP 728, closed=True) |
Python API
For more control, use the library directly:
from openapi_httpx import Config, generate
result = generate("path/to/openapi.yaml", Config(
async_client=True,
client_class_name="MyApiClient",
))
with open("client.py", "w") as f:
f.write(result)
See the Config class for all available options.
Differences to plain HTTPX
This library is an extremely thin wrapper around the HTTPX Client class. But there are a few notable differences:
- Path parameters are passed to the
paramsargument alongside query parameters. You cannot use f-strings to interpolate them, or the type checking will break! - The methods don't return
[Response](https://www.python-httpx.org/api/#response)s but instead return the parsed response body. The response is automatically parsed based on theparse_asargument which defaults to'json'. It can also be set to'text'to return astrorNoneto return rawbytes. - The library automatically calls
[raise_for_status](https://www.python-httpx.org/quickstart/#response-status-codes)on the response, which means that any unsuccessful status code will raise an exception. To customize exceptions, you can pass[event_hooks](https://www.python-httpx.org/advanced/event-hooks/)at client registration time.
Prior Art
Inspired by OpenAPI fetch for TypeScript.
Built on top of datamodel-code-generator which handles most of the heavy lifting of parsing the OpenAPI specification.
Development
See CONTRIBUTING.md for development setup and guidelines.
Metadata
Release files for openapi-httpx 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openapi_httpx-0.1.2.tar.gz | 13.8 kB | With provenance | Details for openapi_httpx-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openapi_httpx-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for openapi_httpx-0.1.2-py3-none-any.whl |
Total release size: 27.7 kB
Release files / openapi_httpx-0.1.2.tar.gz
| Download URL | openapi_httpx-0.1.2.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b6861b1ecd6b3d83f690a4e7a35a4137602332d332be46184899b486fa49937
|
|
BLAKE2b-256 checksum How to use checksums |
926aa40f6bf91be2e24fdf62df6f5875195920193994e92a246397fac12a3242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / openapi_httpx-0.1.2-py3-none-any.whl
| Download URL | openapi_httpx-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef1760a68b7bce43c2d4f5ca24edffcb34878870ca7e33ba644a1a50f90bacb3
|
|
BLAKE2b-256 checksum How to use checksums |
b2183fb22a7bac2e1fb811bff6542c784d35ae85d3bebf1a5f82ccf09ee3dd45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logSecurity for openapi-httpx 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for openapi_httpx-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.