Record and replay niquests HTTP and WebSocket interactions in pytest
Project description
nimax
Record and replay niquests HTTP and WebSocket interactions in pytest.
nimax is a VCR-style cassette library built natively for niquests — supporting lazy responses, multiplexed connections, AsyncSession, and WebSockets. It is to niquests what betamax is to requests.
Installation
pip install nimax
Quick start
Automatic fixture
nimax registers a nimax_session pytest fixture automatically. Use it instead of niquests.Session() in your tests:
def test_my_api(nimax_session):
resp = nimax_session.get("https://api.example.com/users")
assert resp.status_code == 200
On the first run nimax records the real HTTP response to a cassette file under cassettes/<test_module>/<test_name>.json. Subsequent runs replay from the cassette — no network required.
Async sessions
import pytest
import niquests
async def test_async(nimax_session):
async with niquests.AsyncSession() as session:
with NimaxRecorder(session).use_cassette("my_cassette.json"):
resp = await session.get("https://api.example.com/data")
assert resp.status_code == 200
Programmatic API
import niquests
from nimax import NimaxRecorder, RecordMode
def test_programmatic(tmp_path):
session = niquests.Session()
cassette_path = tmp_path / "my_cassette.json"
with NimaxRecorder(session).use_cassette(cassette_path, record_mode=RecordMode.ONCE):
resp = session.get("https://api.example.com/users")
assert resp.status_code == 200
Record modes
| Mode | Behaviour |
|---|---|
once |
Record on first run, replay on subsequent runs (default) |
none |
Never record — raise an error if no matching interaction exists |
new_episodes |
Replay existing interactions; record any unmatched requests |
all |
Always record, overwriting the cassette each run |
Placeholders
Scrub sensitive values (tokens, API keys) from cassettes before they are written:
from nimax import Placeholder
recorder = NimaxRecorder(session, placeholders=[
Placeholder(placeholder="<AUTH_TOKEN>", replace="Bearer secret123"),
])
Custom matchers and serializers
from nimax import BaseMatcher, NimaxRecorder
class BodyMatcher(BaseMatcher):
name = "body"
def match(self, recorded: dict, live: object) -> bool:
return recorded.get("body") == live.body # type: ignore[union-attr]
NimaxRecorder.register_matcher(BodyMatcher)
YAML cassettes are supported out of the box — use a .yaml extension for the cassette path.
Requirements
- Python ≥ 3.11
- niquests ≥ 3
- pytest ≥ 8
- PyYAML ≥ 6
License
MIT
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 nimax-1.0.0.tar.gz.
File metadata
- Download URL: nimax-1.0.0.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d413fae3c0da2b2c0a8cddb77619f1a80d65a085314d0fb84c783879e3408df
|
|
| MD5 |
b5424dffd6f404205fb195353efebf5b
|
|
| BLAKE2b-256 |
7cdeb312930831e306bf7159b3caaca2c0ae37b6d265b1369443af6cf891c779
|
Provenance
The following attestation bundles were made for nimax-1.0.0.tar.gz:
Publisher:
publish.yml on adamlogan73/nimax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nimax-1.0.0.tar.gz -
Subject digest:
6d413fae3c0da2b2c0a8cddb77619f1a80d65a085314d0fb84c783879e3408df - Sigstore transparency entry: 1344537591
- Sigstore integration time:
-
Permalink:
adamlogan73/nimax@b92d9b48374c281485a37d6b1efb3af95fd272ad -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/adamlogan73
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b92d9b48374c281485a37d6b1efb3af95fd272ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file nimax-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nimax-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e508a2944134025707ad70c69b7abe62df4572d6ee5b7416d8907a1d88391c28
|
|
| MD5 |
eb53f459871c1b201dab250a9c3f4858
|
|
| BLAKE2b-256 |
8f0eb37d3e6b66a3bfbf295a30f148645196237cd29f340a7b54ce27b67a4d83
|
Provenance
The following attestation bundles were made for nimax-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on adamlogan73/nimax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nimax-1.0.0-py3-none-any.whl -
Subject digest:
e508a2944134025707ad70c69b7abe62df4572d6ee5b7416d8907a1d88391c28 - Sigstore transparency entry: 1344537720
- Sigstore integration time:
-
Permalink:
adamlogan73/nimax@b92d9b48374c281485a37d6b1efb3af95fd272ad -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/adamlogan73
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b92d9b48374c281485a37d6b1efb3af95fd272ad -
Trigger Event:
push
-
Statement type: