Skip to main content

Serve an OpenAPI spec as a mock with respx.

Project description

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)

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)

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

Project details


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.3.2.tar.gz (111.5 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.3.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openapi_mock-2026.3.2.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openapi_mock-2026.3.2.tar.gz
Algorithm Hash digest
SHA256 c87c16e683a3a0fc3483e60100592033cba6cb4559c366d1e02e6b1166e24d8d
MD5 b30dc49dcf367821d71eedb2da705de0
BLAKE2b-256 07e2b6c9cda517cfdbae46a0d4bc39b280378b35abfddc4b61704923b9bca8de

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_mock-2026.3.2.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.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_mock-2026.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 739168ee76c6821b5296453508ed1de6ec0c4c7fa6819d7ee0c3d13bcc364cf2
MD5 89a8e3231a761e307c02bc658f3e31cf
BLAKE2b-256 137edc3b12703eae1f1b35637f795dcf9732587e75d93594ed826428c7edfda9

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_mock-2026.3.2-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 Pingdom Monitoring Sentry Error logging StatusPage Status page