Skip to main content

nimax

CI codecov PyPI

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

Download files

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

Source Distribution

nimax-1.0.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

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

nimax-1.0.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

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

Hashes for nimax-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6d413fae3c0da2b2c0a8cddb77619f1a80d65a085314d0fb84c783879e3408df
MD5 b5424dffd6f404205fb195353efebf5b
BLAKE2b-256 7cdeb312930831e306bf7159b3caaca2c0ae37b6d265b1369443af6cf891c779

See more details on using hashes here.

Provenance

The following attestation bundles were made for nimax-1.0.0.tar.gz:

Publisher: publish.yml on adamlogan73/nimax

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

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

Hashes for nimax-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e508a2944134025707ad70c69b7abe62df4572d6ee5b7416d8907a1d88391c28
MD5 eb53f459871c1b201dab250a9c3f4858
BLAKE2b-256 8f0eb37d3e6b66a3bfbf295a30f148645196237cd29f340a7b54ce27b67a4d83

See more details on using hashes here.

Provenance

The following attestation bundles were made for nimax-1.0.0-py3-none-any.whl:

Publisher: publish.yml on adamlogan73/nimax

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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

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