Serve an OpenAPI spec as a mock with respx.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c87c16e683a3a0fc3483e60100592033cba6cb4559c366d1e02e6b1166e24d8d
|
|
| MD5 |
b30dc49dcf367821d71eedb2da705de0
|
|
| BLAKE2b-256 |
07e2b6c9cda517cfdbae46a0d4bc39b280378b35abfddc4b61704923b9bca8de
|
Provenance
The following attestation bundles were made for openapi_mock-2026.3.2.tar.gz:
Publisher:
release.yml on adamtheturtle/openapi-mock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_mock-2026.3.2.tar.gz -
Subject digest:
c87c16e683a3a0fc3483e60100592033cba6cb4559c366d1e02e6b1166e24d8d - Sigstore transparency entry: 1008360744
- Sigstore integration time:
-
Permalink:
adamtheturtle/openapi-mock@315e41e8e87a159388b96d7377f308f4058de216 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@315e41e8e87a159388b96d7377f308f4058de216 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openapi_mock-2026.3.2-py3-none-any.whl.
File metadata
- Download URL: openapi_mock-2026.3.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
739168ee76c6821b5296453508ed1de6ec0c4c7fa6819d7ee0c3d13bcc364cf2
|
|
| MD5 |
89a8e3231a761e307c02bc658f3e31cf
|
|
| BLAKE2b-256 |
137edc3b12703eae1f1b35637f795dcf9732587e75d93594ed826428c7edfda9
|
Provenance
The following attestation bundles were made for openapi_mock-2026.3.2-py3-none-any.whl:
Publisher:
release.yml on adamtheturtle/openapi-mock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_mock-2026.3.2-py3-none-any.whl -
Subject digest:
739168ee76c6821b5296453508ed1de6ec0c4c7fa6819d7ee0c3d13bcc364cf2 - Sigstore transparency entry: 1008360751
- Sigstore integration time:
-
Permalink:
adamtheturtle/openapi-mock@315e41e8e87a159388b96d7377f308f4058de216 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@315e41e8e87a159388b96d7377f308f4058de216 -
Trigger Event:
workflow_dispatch
-
Statement type: