Skip to main content

openapi-mock

Build Status PyPI

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)

Source distribution for openapi-mock 2026.10.9
File Size Uploaded
openapi_mock-2026.10.9.tar.gz 135.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openapi-mock 2026.10.9
File Interpreter ABI Platform
openapi_mock-2026.10.9-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

2026.10.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page