Skip to main content

Build Status PyPI

Serve an OpenAPI spec as a mock with respx or responses.

Installation

uv pip install openapi-mock

Or with pip:

pip install openapi-mock

Usage

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_mock-2026.8.16.tar.gz (129.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_mock-2026.8.16-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file openapi_mock-2026.8.16.tar.gz.

File metadata

  • Download URL: openapi_mock-2026.8.16.tar.gz
  • Upload date:
  • Size: 129.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for openapi_mock-2026.8.16.tar.gz
Algorithm Hash digest
SHA256 9dc422d138a1d84d3470fe76d4c0d49a33c16400369b5ddcaf93bfd02e5c035d
MD5 c07dae35a7a28ff30ae7efab7d048af5
BLAKE2b-256 6e5bc3482e3a2dccb28484546ee6ad0a3ff0f88a8aa439127e147ef9294ae8d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_mock-2026.8.16.tar.gz:

Publisher: release.yml on adamtheturtle/openapi-mock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_mock-2026.8.16-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_mock-2026.8.16-py3-none-any.whl
Algorithm Hash digest
SHA256 0c7af495030f93ab17aa2788e66891c1dcbfaf766199cb06da599558097eaf4d
MD5 12ce62ff9ec0ffd6913461b9f7de817d
BLAKE2b-256 cbabd2b1edf17a21f88b5dc1041f0775a28fbcccf1abd1af81f27aafa73660d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_mock-2026.8.16-py3-none-any.whl:

Publisher: release.yml on adamtheturtle/openapi-mock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page