> ## Documentation Index
> Fetch the complete documentation index at: https://evalvcr.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python & pytest Companion

> Pure-Python stdlib VCR engine, pytest11 plugin, and cross-language cassette interop.

`python/evalvcr` implements the exact `evalvcr.cassette.v1` and `evalvcr.report.v1` JSON schemas using Python `>= 3.10` standard library only (`pytest` is optional).

## Install

```bash theme={null}
pip install "evalvcr[pytest]"
# Or pure stdlib without pytest:
pip install evalvcr
```

## Using with `pytest`

`evalvcr` registers a `pytest11` entry point exposing:

* CLI options: `--evalvcr-mode` (default `replay`) and `--evalvcr-cassette-dir` (default `.evalvcr/cassettes`)
* Marker: `@pytest.mark.evalvcr(cassette="my-case")` (omit `mode` so CLI flags control `auto` locally vs `strict` in CI)
* Fixture: `evalvcr_cassette` (yields `CassetteVCR`, saves on teardown in `record`/`auto`, and runs `verify_complete()` in `strict` mode)

```python theme={null}
import pytest
from evalvcr import CassetteVCR, exact_match


@pytest.mark.evalvcr(cassette="weather-lookup")
def test_weather(evalvcr_cassette: CassetteVCR) -> None:
    res = evalvcr_cassette.interact(
        kind="llm.chat",
        provider="openai",
        request={"method": "POST", "target": "/v1/chat/completions", "body": {"q": "Hanoi"}},
        execute=lambda: {"response": {"status": 200, "sdk": {"text": "28C Sunny"}}},
    )
    assert exact_match()({"output": res["response"]["sdk"]["text"], "expected": "28C Sunny"})["score"] == 1.0
```

Record once locally and enforce strict replay in CI:

```bash theme={null}
pytest --evalvcr-mode=auto --evalvcr-cassette-dir=.evalvcr/cassettes
pytest --evalvcr-mode=strict --evalvcr-cassette-dir=.evalvcr/cassettes
```

## Using the Python CLI

Run `define_eval(...)` suites or inspect/scrub/export artifacts directly:

```bash theme={null}
evalvcr --version
python -m evalvcr run ./evals --mode strict
python -m evalvcr inspect .evalvcr/cassettes/weather-lookup.evalvcr.json
python -m evalvcr scrub .evalvcr/cassettes/weather-lookup.evalvcr.json --write
python -m evalvcr export report.json --format sarif --output evalvcr.sarif
```

## Cross-Language Interoperability

Because Python and TypeScript share UTF-16 code-unit JCS canonical JSON sorting, ASCII scrubbing order, and camelCase JSON fields, cassettes recorded in TypeScript replay strictly in Python and vice versa. See [`examples/python-pytest/test_support_agent.py`](https://github.com/evalvcr/evalvcr/blob/main/examples/python-pytest/test_support_agent.py) for a live cross-language replay test.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.