Skip to main content

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.9.7

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.9.7
File Size Uploaded
openapi_mock-2026.9.7.tar.gz 131.8 kB Details

Built distribution (wheel)

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

Total release size: 140.1 kB

Release files / openapi_mock-2026.9.7.tar.gz

Download URL openapi_mock-2026.9.7.tar.gz
Size 131.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2a52c42229d0733128269ab45d26644715c03f52e2855e6e48ded8e561f2c48f
BLAKE2b-256 checksum
How to use checksums
2fff6a826ba2493ef51bef18f324661e319c8a149b27a82aaf8f83bceb2b56fd
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 Sep 7, 2026.

Transparency log

Release files / openapi_mock-2026.9.7-py3-none-any.whl

Download URL openapi_mock-2026.9.7-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d48ca4b626f1fe84a79ce21b087dabe6ca52c6392aede4d6fd7b227adf30b485
BLAKE2b-256 checksum
How to use checksums
cda1f5ab96880360365686c975c80c507616a7f8a3da3adc14fc2ec6dfc3cf39
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 Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2026.9.7 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