openapi-mock
Serve an OpenAPI spec as a mock with HTTPX2, respx or responses.
Installation
uv pip install openapi-mock
Or with pip:
pip install openapi-mock
Usage
With HTTPX2
"""Example usage with HTTPX2."""
from http import HTTPStatus
import httpx2
from openapi_mock import create_httpx2_transport
spec = {
"openapi": "3.0.0",
"paths": {"/pets": {"get": {"responses": {"200": {"description": "OK"}}}}},
}
transport = create_httpx2_transport(
spec=spec,
base_url="https://api.example.com",
)
with httpx2.Client(transport=transport) as client:
response = client.get(url="https://api.example.com/pets")
assert response.status_code == HTTPStatus.OK
With respx (httpx)
"""Example usage with respx."""
from http import HTTPStatus
import httpx
import respx
from openapi_mock import add_openapi_to_respx
spec = {
"openapi": "3.0.0",
"paths": {"/pets": {"get": {"responses": {"200": {"description": "OK"}}}}},
}
with respx.mock(base_url="https://api.example.com", assert_all_called=False) as m:
add_openapi_to_respx(mock_obj=m, spec=spec, base_url="https://api.example.com")
response = httpx.get(url="https://api.example.com/pets")
assert response.status_code == HTTPStatus.OK
With responses (requests)
"""Example usage with responses."""
from http import HTTPStatus
import requests
import responses
from openapi_mock import add_openapi_to_responses
spec = {
"openapi": "3.0.0",
"paths": {"/pets": {"get": {"responses": {"200": {"description": "OK"}}}}},
}
with responses.RequestsMock() as rsps:
add_openapi_to_responses(spec=spec, base_url="https://api.example.com", mock=rsps)
response = requests.get(url="https://api.example.com/pets", timeout=30)
assert response.status_code == HTTPStatus.OK
Metadata
Release files for openapi-mock 2026.10.9
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_mock-2026.10.9.tar.gz | 135.9 kB | With provenance | Details for openapi_mock-2026.10.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openapi_mock-2026.10.9-py3-none-any.whl | Python 3 | none | any | Details for openapi_mock-2026.10.9-py3-none-any.whl |
Total release size: 144.0 kB
Release files / openapi_mock-2026.10.9.tar.gz
| Download URL | openapi_mock-2026.10.9.tar.gz |
|---|---|
| Size | 135.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfba53282ede8a534e4f6c068ca77e06f060e01fda2b23caebe0e491142cbdff
|
|
BLAKE2b-256 checksum How to use checksums |
294dd36ed592d24a914066ab1e9bb1a8ec3cc0dd6e7d73b272adc9089181d76b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 9, 2026.
Transparency logRelease files / openapi_mock-2026.10.9-py3-none-any.whl
| Download URL | openapi_mock-2026.10.9-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
058ba43b1d455f263d50c5e66ba0fb861a32e083efeefcf64767cbfdeef373eb
|
|
BLAKE2b-256 checksum How to use checksums |
e1e537903c2a9466a697a0e9aef548c5c87c68255f621bc0d1f1ebeba82c5f0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 9, 2026.
Transparency logSecurity for openapi-mock 2026.10.9
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
Both files in this release have been uploaded with provenance metadata.
Attestation for openapi_mock-2026.10.9.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 Oct 9, 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.