standin 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. standin-0.2.0/.gitignore +14 -0
  2. standin-0.2.0/ARCHITECTURE.md +73 -0
  3. standin-0.2.0/CHANGELOG.md +37 -0
  4. standin-0.2.0/LICENSE +21 -0
  5. standin-0.2.0/PKG-INFO +182 -0
  6. standin-0.2.0/README.md +146 -0
  7. standin-0.2.0/demo/README.md +44 -0
  8. standin-0.2.0/pyproject.toml +68 -0
  9. standin-0.2.0/standin/__init__.py +42 -0
  10. standin-0.2.0/standin/_codec.py +81 -0
  11. standin-0.2.0/standin/cassette.py +40 -0
  12. standin-0.2.0/standin/cli.py +112 -0
  13. standin-0.2.0/standin/config.py +41 -0
  14. standin-0.2.0/standin/core.py +68 -0
  15. standin-0.2.0/standin/engine.py +105 -0
  16. standin-0.2.0/standin/exceptions.py +22 -0
  17. standin-0.2.0/standin/interceptors/__init__.py +11 -0
  18. standin-0.2.0/standin/interceptors/base.py +35 -0
  19. standin-0.2.0/standin/interceptors/httpx_interceptor.py +89 -0
  20. standin-0.2.0/standin/matching.py +89 -0
  21. standin-0.2.0/standin/models.py +63 -0
  22. standin-0.2.0/standin/py.typed +1 -0
  23. standin-0.2.0/standin/pytest_plugin.py +37 -0
  24. standin-0.2.0/standin/redaction.py +73 -0
  25. standin-0.2.0/standin/storage.py +82 -0
  26. standin-0.2.0/tests/conftest.py +123 -0
  27. standin-0.2.0/tests/integration/test_anthropic_sdk.py +33 -0
  28. standin-0.2.0/tests/integration/test_async.py +70 -0
  29. standin-0.2.0/tests/integration/test_edge_cases.py +112 -0
  30. standin-0.2.0/tests/integration/test_modes.py +74 -0
  31. standin-0.2.0/tests/integration/test_openai_sdk.py +48 -0
  32. standin-0.2.0/tests/integration/test_pytest_plugin.py +43 -0
  33. standin-0.2.0/tests/integration/test_record_replay.py +73 -0
  34. standin-0.2.0/tests/integration/test_threads.py +36 -0
  35. standin-0.2.0/tests/property/test_fuzz.py +53 -0
  36. standin-0.2.0/tests/unit/test_cassette.py +43 -0
  37. standin-0.2.0/tests/unit/test_cli.py +49 -0
  38. standin-0.2.0/tests/unit/test_codec.py +35 -0
  39. standin-0.2.0/tests/unit/test_config.py +26 -0
  40. standin-0.2.0/tests/unit/test_fuzzy.py +40 -0
  41. standin-0.2.0/tests/unit/test_hardening.py +85 -0
  42. standin-0.2.0/tests/unit/test_matching.py +31 -0
  43. standin-0.2.0/tests/unit/test_redaction.py +32 -0
  44. standin-0.2.0/tests/unit/test_storage.py +40 -0
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .pytest_cache/
7
+ .hypothesis/
8
+ .mypy_cache/
9
+ .venv/
10
+ venv/
11
+ .env
12
+ .DS_Store
13
+ demo/.cache/
14
+ demo/cassettes/
@@ -0,0 +1,73 @@
1
+ # Architecture
2
+
3
+ `standin` is organized as a set of small, single-responsibility layers. The
4
+ guiding rule: **the record/replay policy never knows which HTTP client it is
5
+ sitting behind.** That keeps the decision logic tiny and testable, and makes new
6
+ clients (or storage formats, matchers, redactors) additive rather than invasive.
7
+
8
+ ## Layers
9
+
10
+ ```
11
+ use_cassette() <- public API (core.py)
12
+
13
+
14
+ ┌─────────────── Engine ───────────────┐ <- policy (engine.py)
15
+ │ record vs replay, ordering, misses │
16
+ └───┬───────────┬───────────┬─────────────┘
17
+ │ │ │
18
+ Matcher Redactor CassetteStore <- pluggable protocols
19
+ (matching) (redaction) (storage)
20
+ │ │ │
21
+ ▼ ▼ ▼
22
+ Cassette ── Interaction / Recorded{Request,Response}
23
+ (models.py, _codec.py)
24
+
25
+ │ RawRequest / RawResponse (transport-neutral)
26
+
27
+ ┌─────┴───────────────┐
28
+ │ Interceptor │ <- transport glue (interceptors/)
29
+ │ HttpxInterceptor │
30
+ └─────────────────────┘
31
+
32
+ httpx.HTTPTransport (patched once, inert until a cassette is open)
33
+ ```
34
+
35
+ ## Modules
36
+
37
+ | Module | Responsibility |
38
+ | --- | --- |
39
+ | `models.py` | Data types. `RawRequest/RawResponse` (in-flight, bytes) vs `RecordedRequest/RecordedResponse/Interaction` (on disk). `Mode` enum. |
40
+ | `_codec.py` | Body encode/decode + canonicalization for matching. |
41
+ | `redaction.py` | `Redactor` protocol; `DefaultRedactor` (headers + secret patterns), `NullRedactor`. |
42
+ | `matching.py` | `Matcher` protocol; `DefaultMatcher` (method/url/body, JSON-aware). |
43
+ | `storage.py` | `CassetteStore` protocol; `JSONCassetteStore`. |
44
+ | `cassette.py` | In-memory interactions + the ordered replay cursor. |
45
+ | `config.py` | Wires the pieces; validates `mode`; picks the redactor. |
46
+ | `engine.py` | The **policy**: replay-or-record, per `Mode`. Transport-neutral. |
47
+ | `interceptors/` | Adapters from a concrete client to the engine. `HttpxInterceptor` today. |
48
+ | `core.py` | `use_cassette` context manager: build config → engine → activate. |
49
+ | `pytest_plugin.py` | `standin` fixture + `@pytest.mark.standin`. |
50
+
51
+ ## Data flow
52
+
53
+ **Record** (cache miss): interceptor converts the client request to a
54
+ `RawRequest` → engine calls `do_real` (the real network call) → response is
55
+ redacted, encoded, appended to the cassette → returned to the client.
56
+
57
+ **Replay** (cache hit): interceptor builds the `RawRequest` → engine matches it
58
+ against an unplayed `Interaction` → decodes the stored response → returns it,
59
+ **without any network call**.
60
+
61
+ The active engine lives in a `ContextVar`, so recording is correct across threads
62
+ and asyncio, and the httpx patch is completely inert whenever no cassette is open.
63
+
64
+ ## Extension points
65
+
66
+ Every collaborator is a `Protocol`, so you can pass your own:
67
+
68
+ - **Interceptor** — support another client (`requests`, `aiohttp`). The engine
69
+ is already transport-neutral; you only translate that client's request/response
70
+ to `RawRequest`/`RawResponse`.
71
+ - **Matcher** — change when a live request equals a recording (e.g. semantic).
72
+ - **Redactor** — change what gets scrubbed.
73
+ - **CassetteStore** — change the on-disk format (YAML, a single archive, ...).
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/), and the project adheres to
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2026-09-05
10
+
11
+ ### Added
12
+ - `standin` command-line tool: `list`, `show`, `stats`, and `scrub` (re-run
13
+ secret redaction over an existing cassette).
14
+ - `FuzzyMatcher`: match method/url exactly but allow the request body to differ
15
+ up to a similarity threshold, so a reworded/reformatted prompt still replays.
16
+ A semantic/embedding matcher plugs in the same way (implement `matches`).
17
+ - Runnable examples for OpenAI and LangChain under `examples/`.
18
+
19
+ ### Changed
20
+ - The `Matcher` protocol is now a single `matches(live, stored)` predicate
21
+ (exact and fuzzy strategies share the cassette lookup). `DefaultMatcher` keeps
22
+ its `live_key`/`stored_key` helpers.
23
+
24
+ ## [0.1.0] - 2026-09-05
25
+
26
+ ### Added
27
+ - `use_cassette` context manager and a `standin` pytest fixture / marker.
28
+ - Provider-agnostic record & replay via an httpx transport interceptor
29
+ (OpenAI, Anthropic, Gemini, Mistral, Cohere, litellm, LangChain, LlamaIndex).
30
+ - Streaming (SSE) record and replay.
31
+ - Automatic redaction of auth headers and secret tokens in cassettes.
32
+ - VCR-style modes: `once`, `none`, `all`, `new_episodes`; `STANDIN_MODE` override.
33
+ - JSON-body-aware matching; ordered replay for repeated calls (agent loops).
34
+ - Pluggable `Matcher`, `Redactor`, and `CassetteStore` protocols.
35
+
36
+ [Unreleased]: https://github.com/eeshsaxena/standin/compare/v0.1.0...HEAD
37
+ [0.1.0]: https://github.com/eeshsaxena/standin/releases/tag/v0.1.0
standin-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eesh Saxena
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
standin-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.5
2
+ Name: standin
3
+ Version: 0.2.0
4
+ Summary: A stand-in for the real LLM in your tests. Record LLM API calls once, replay them forever: fast, free, deterministic, offline.
5
+ Project-URL: Homepage, https://github.com/eeshsaxena/standin
6
+ Project-URL: Source, https://github.com/eeshsaxena/standin
7
+ Project-URL: Issues, https://github.com/eeshsaxena/standin/issues
8
+ Project-URL: Changelog, https://github.com/eeshsaxena/standin/blob/main/CHANGELOG.md
9
+ Author-email: Eesh Saxena <eeshsaxena@gmail.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,ai,anthropic,cassette,deterministic,llm,mock,openai,pytest,record,replay,testing,vcr
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: Pytest
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Software Development :: Testing
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.9
27
+ Requires-Dist: httpx>=0.23
28
+ Provides-Extra: dev
29
+ Requires-Dist: anthropic>=0.30; extra == 'dev'
30
+ Requires-Dist: hypothesis>=6; extra == 'dev'
31
+ Requires-Dist: mypy>=1.8; extra == 'dev'
32
+ Requires-Dist: openai>=1.0; extra == 'dev'
33
+ Requires-Dist: pytest>=7; extra == 'dev'
34
+ Requires-Dist: ruff>=0.5; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # standin
38
+
39
+ **A stand-in for the real LLM in your tests.** Record your LLM API calls once, then replay them forever: fast, free, deterministic, and fully offline. One line, any provider.
40
+
41
+ <p align="center"><img src="demo/standin.gif" alt="standin: record LLM calls once, replay them instantly and offline" width="820"></p>
42
+
43
+ ```python
44
+ import standin
45
+
46
+ with standin.use_cassette("tests/cassettes/summary.json"):
47
+ reply = client.chat.completions.create(model="gpt-4o", messages=[...])
48
+ # First run: hits the real API and records it.
49
+ # Every run after: replayed from disk. No network, no cost, same answer.
50
+ ```
51
+
52
+ Your LLM tests are slow, flaky, and cost money because they hit real APIs. `standin` makes them **deterministic and offline** by recording the real HTTP calls once and replaying them after, with the things LLM devs actually need: **streaming**, **tool-calls**, **secret redaction**, and **body-aware matching**.
53
+
54
+ ---
55
+
56
+ ## Why not just VCR.py?
57
+
58
+ VCR.py is great, but it's a general HTTP tool. `standin` is built for LLMs:
59
+
60
+ - **Provider-agnostic, zero wiring.** It hooks `httpx` under the hood, so it works with **OpenAI, Anthropic, Gemini, Mistral, Cohere, litellm, LangChain, LlamaIndex** — anything that sends over httpx. No per-SDK adapters.
61
+ - **Streaming just works.** Server-sent event (SSE) responses are recorded and replayed intact.
62
+ - **Safe to commit.** API keys in headers and secret-looking tokens in bodies are **redacted automatically**, so cassettes can live in a public repo.
63
+ - **Body-aware matching.** Requests match on normalized JSON, so key ordering and formatting noise don't break replays. Repeated identical calls (agent loops) replay in order.
64
+ - **One-line pytest fixture**, with sane auto-named cassettes.
65
+ - **Clean, typed, extensible core** (see [ARCHITECTURE.md](ARCHITECTURE.md)) — swap the matcher, redactor, or storage backend.
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pip install standin
71
+ ```
72
+
73
+ Python 3.9+ and `httpx` (already a dependency of the major LLM SDKs).
74
+
75
+ ## Quickstart
76
+
77
+ ### With pytest (recommended)
78
+
79
+ ```python
80
+ import pytest
81
+
82
+ @pytest.mark.standin # cassette auto-named tests/cassettes/test_summarize.json
83
+ def test_summarize(standin):
84
+ out = summarize("war and peace") # your code that calls an LLM
85
+ assert "Napoleon" in out
86
+ ```
87
+
88
+ First run records against the real API; every run after replays from the cassette. Commit the cassette and teammates (and CI) run the test with **no keys and no network**.
89
+
90
+ ### Anywhere (context manager)
91
+
92
+ ```python
93
+ import standin
94
+ from openai import OpenAI
95
+
96
+ client = OpenAI()
97
+ with standin.use_cassette("tests/cassettes/haiku.json"):
98
+ resp = client.chat.completions.create(
99
+ model="gpt-4o-mini",
100
+ messages=[{"role": "user", "content": "haiku about testing"}],
101
+ )
102
+ ```
103
+
104
+ ## Modes
105
+
106
+ | Mode | Behavior |
107
+ | --- | --- |
108
+ | `once` (default) | Replay if the cassette exists, otherwise record it. |
109
+ | `none` | Replay only. **Errors on any unrecorded call** — use this in CI. |
110
+ | `all` | Always re-record, ignoring existing interactions. |
111
+ | `new_episodes` | Replay what's recorded, record anything new (great for agent loops). |
112
+
113
+ **In CI**, force replay-only for the whole run so a stray live call fails loudly:
114
+
115
+ ```bash
116
+ STANDIN_MODE=none pytest
117
+ ```
118
+
119
+ ## What a cassette looks like
120
+
121
+ Plain, reviewable JSON, secrets already stripped:
122
+
123
+ ```json
124
+ {
125
+ "version": 1,
126
+ "recorded_with": "standin",
127
+ "interactions": [
128
+ {
129
+ "request": {
130
+ "method": "POST",
131
+ "url": "https://api.openai.com/v1/chat/completions",
132
+ "headers": { "authorization": "[REDACTED]" },
133
+ "body": { "json": { "model": "gpt-4o-mini", "messages": [ ] } }
134
+ },
135
+ "response": { "status_code": 200, "body": { "json": { "choices": [ ] } } }
136
+ }
137
+ ]
138
+ }
139
+ ```
140
+
141
+ ## Extending it
142
+
143
+ Everything is a small protocol you can replace (see [ARCHITECTURE.md](ARCHITECTURE.md)):
144
+
145
+ ```python
146
+ standin.use_cassette(path, matcher=MyMatcher(), redactor=MyRedactor(), store=MyStore())
147
+ ```
148
+
149
+ - **Matcher** — decide when a live request equals a recorded one. Ships with
150
+ `DefaultMatcher` (exact) and `FuzzyMatcher` (body may drift up to a similarity
151
+ threshold, so a reworded prompt still replays):
152
+
153
+ ```python
154
+ from standin import use_cassette, FuzzyMatcher, DefaultRedactor
155
+ with use_cassette(path, matcher=FuzzyMatcher(DefaultRedactor(), threshold=0.9)):
156
+ ...
157
+ ```
158
+ - **Redactor** — control what gets scrubbed before writing.
159
+ - **CassetteStore** — change the on-disk format.
160
+
161
+ ## Command line
162
+
163
+ ```bash
164
+ standin list tests/cassettes/summary.json # one line per interaction
165
+ standin show tests/cassettes/summary.json 0 # full request/response
166
+ standin stats tests/cassettes/summary.json # counts by method/status
167
+ standin scrub tests/cassettes/summary.json # re-run secret redaction in place
168
+ ```
169
+
170
+ ## Roadmap
171
+
172
+ - Embedding-based semantic matching (a `Matcher` you drop in; `FuzzyMatcher`
173
+ already covers string-similarity drift today).
174
+ - `requests` / `aiohttp` interceptors (the engine is already transport-neutral).
175
+
176
+ ## Contributing
177
+
178
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Run the suite with `pytest`, lint with `ruff`, type-check with `mypy`.
179
+
180
+ ## License
181
+
182
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,146 @@
1
+ # standin
2
+
3
+ **A stand-in for the real LLM in your tests.** Record your LLM API calls once, then replay them forever: fast, free, deterministic, and fully offline. One line, any provider.
4
+
5
+ <p align="center"><img src="demo/standin.gif" alt="standin: record LLM calls once, replay them instantly and offline" width="820"></p>
6
+
7
+ ```python
8
+ import standin
9
+
10
+ with standin.use_cassette("tests/cassettes/summary.json"):
11
+ reply = client.chat.completions.create(model="gpt-4o", messages=[...])
12
+ # First run: hits the real API and records it.
13
+ # Every run after: replayed from disk. No network, no cost, same answer.
14
+ ```
15
+
16
+ Your LLM tests are slow, flaky, and cost money because they hit real APIs. `standin` makes them **deterministic and offline** by recording the real HTTP calls once and replaying them after, with the things LLM devs actually need: **streaming**, **tool-calls**, **secret redaction**, and **body-aware matching**.
17
+
18
+ ---
19
+
20
+ ## Why not just VCR.py?
21
+
22
+ VCR.py is great, but it's a general HTTP tool. `standin` is built for LLMs:
23
+
24
+ - **Provider-agnostic, zero wiring.** It hooks `httpx` under the hood, so it works with **OpenAI, Anthropic, Gemini, Mistral, Cohere, litellm, LangChain, LlamaIndex** — anything that sends over httpx. No per-SDK adapters.
25
+ - **Streaming just works.** Server-sent event (SSE) responses are recorded and replayed intact.
26
+ - **Safe to commit.** API keys in headers and secret-looking tokens in bodies are **redacted automatically**, so cassettes can live in a public repo.
27
+ - **Body-aware matching.** Requests match on normalized JSON, so key ordering and formatting noise don't break replays. Repeated identical calls (agent loops) replay in order.
28
+ - **One-line pytest fixture**, with sane auto-named cassettes.
29
+ - **Clean, typed, extensible core** (see [ARCHITECTURE.md](ARCHITECTURE.md)) — swap the matcher, redactor, or storage backend.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pip install standin
35
+ ```
36
+
37
+ Python 3.9+ and `httpx` (already a dependency of the major LLM SDKs).
38
+
39
+ ## Quickstart
40
+
41
+ ### With pytest (recommended)
42
+
43
+ ```python
44
+ import pytest
45
+
46
+ @pytest.mark.standin # cassette auto-named tests/cassettes/test_summarize.json
47
+ def test_summarize(standin):
48
+ out = summarize("war and peace") # your code that calls an LLM
49
+ assert "Napoleon" in out
50
+ ```
51
+
52
+ First run records against the real API; every run after replays from the cassette. Commit the cassette and teammates (and CI) run the test with **no keys and no network**.
53
+
54
+ ### Anywhere (context manager)
55
+
56
+ ```python
57
+ import standin
58
+ from openai import OpenAI
59
+
60
+ client = OpenAI()
61
+ with standin.use_cassette("tests/cassettes/haiku.json"):
62
+ resp = client.chat.completions.create(
63
+ model="gpt-4o-mini",
64
+ messages=[{"role": "user", "content": "haiku about testing"}],
65
+ )
66
+ ```
67
+
68
+ ## Modes
69
+
70
+ | Mode | Behavior |
71
+ | --- | --- |
72
+ | `once` (default) | Replay if the cassette exists, otherwise record it. |
73
+ | `none` | Replay only. **Errors on any unrecorded call** — use this in CI. |
74
+ | `all` | Always re-record, ignoring existing interactions. |
75
+ | `new_episodes` | Replay what's recorded, record anything new (great for agent loops). |
76
+
77
+ **In CI**, force replay-only for the whole run so a stray live call fails loudly:
78
+
79
+ ```bash
80
+ STANDIN_MODE=none pytest
81
+ ```
82
+
83
+ ## What a cassette looks like
84
+
85
+ Plain, reviewable JSON, secrets already stripped:
86
+
87
+ ```json
88
+ {
89
+ "version": 1,
90
+ "recorded_with": "standin",
91
+ "interactions": [
92
+ {
93
+ "request": {
94
+ "method": "POST",
95
+ "url": "https://api.openai.com/v1/chat/completions",
96
+ "headers": { "authorization": "[REDACTED]" },
97
+ "body": { "json": { "model": "gpt-4o-mini", "messages": [ ] } }
98
+ },
99
+ "response": { "status_code": 200, "body": { "json": { "choices": [ ] } } }
100
+ }
101
+ ]
102
+ }
103
+ ```
104
+
105
+ ## Extending it
106
+
107
+ Everything is a small protocol you can replace (see [ARCHITECTURE.md](ARCHITECTURE.md)):
108
+
109
+ ```python
110
+ standin.use_cassette(path, matcher=MyMatcher(), redactor=MyRedactor(), store=MyStore())
111
+ ```
112
+
113
+ - **Matcher** — decide when a live request equals a recorded one. Ships with
114
+ `DefaultMatcher` (exact) and `FuzzyMatcher` (body may drift up to a similarity
115
+ threshold, so a reworded prompt still replays):
116
+
117
+ ```python
118
+ from standin import use_cassette, FuzzyMatcher, DefaultRedactor
119
+ with use_cassette(path, matcher=FuzzyMatcher(DefaultRedactor(), threshold=0.9)):
120
+ ...
121
+ ```
122
+ - **Redactor** — control what gets scrubbed before writing.
123
+ - **CassetteStore** — change the on-disk format.
124
+
125
+ ## Command line
126
+
127
+ ```bash
128
+ standin list tests/cassettes/summary.json # one line per interaction
129
+ standin show tests/cassettes/summary.json 0 # full request/response
130
+ standin stats tests/cassettes/summary.json # counts by method/status
131
+ standin scrub tests/cassettes/summary.json # re-run secret redaction in place
132
+ ```
133
+
134
+ ## Roadmap
135
+
136
+ - Embedding-based semantic matching (a `Matcher` you drop in; `FuzzyMatcher`
137
+ already covers string-similarity drift today).
138
+ - `requests` / `aiohttp` interceptors (the engine is already transport-neutral).
139
+
140
+ ## Contributing
141
+
142
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Run the suite with `pytest`, lint with `ruff`, type-check with `mypy`.
143
+
144
+ ## License
145
+
146
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,44 @@
1
+ # Demo
2
+
3
+ Two ways to see `standin` work, both keyless and offline (a local server stands
4
+ in for the OpenAI API with realistic latency).
5
+
6
+ ## The one-liner (used for the README GIF)
7
+
8
+ ```bash
9
+ python demo/demo.py
10
+ ```
11
+
12
+ Records 5 model calls once (~8s), then replays them from the cassette (~0.03s):
13
+
14
+ ```
15
+ 1st run real API calls, recording 8.07s $$$
16
+ every run replayed from cassette 0.029s $0.00 offline
17
+ => 281x faster, deterministic, no network, no keys.
18
+ ```
19
+
20
+ ## The pytest example (the real workflow)
21
+
22
+ ```bash
23
+ pytest demo/test_summary.py -p standin.pytest_plugin -q # first run records
24
+ pytest demo/test_summary.py -p standin.pytest_plugin -q # replays, offline
25
+ ```
26
+
27
+ (The `-p` flag isn't needed once `standin` is `pip install`ed — the plugin loads
28
+ automatically.)
29
+
30
+ ## Regenerating the GIF
31
+
32
+ The GIF is produced from [`demo.tape`](demo.tape) with
33
+ [VHS](https://github.com/charmbracelet/vhs):
34
+
35
+ ```bash
36
+ vhs demo/demo.tape # writes demo/standin.gif
37
+ ```
38
+
39
+ No VHS? Record with [asciinema](https://asciinema.org) instead:
40
+
41
+ ```bash
42
+ asciinema rec -c "python demo/demo.py" demo/standin.cast
43
+ # then: agg demo/standin.cast demo/standin.gif
44
+ ```
@@ -0,0 +1,68 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "standin"
7
+ version = "0.2.0"
8
+ description = "A stand-in for the real LLM in your tests. Record LLM API calls once, replay them forever: fast, free, deterministic, offline."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [{ name = "Eesh Saxena", email = "eeshsaxena@gmail.com" }]
13
+ keywords = ["llm", "testing", "pytest", "openai", "anthropic", "vcr", "cassette", "record", "replay", "mock", "ai", "deterministic", "agents"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Framework :: Pytest",
25
+ "Topic :: Software Development :: Testing",
26
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
27
+ "Typing :: Typed",
28
+ ]
29
+ dependencies = ["httpx>=0.23"]
30
+
31
+ [project.optional-dependencies]
32
+ dev = ["pytest>=7", "ruff>=0.5", "mypy>=1.8", "openai>=1.0", "anthropic>=0.30", "hypothesis>=6"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/eeshsaxena/standin"
36
+ Source = "https://github.com/eeshsaxena/standin"
37
+ Issues = "https://github.com/eeshsaxena/standin/issues"
38
+ Changelog = "https://github.com/eeshsaxena/standin/blob/main/CHANGELOG.md"
39
+
40
+ [project.entry-points.pytest11]
41
+ standin = "standin.pytest_plugin"
42
+
43
+ [project.scripts]
44
+ standin = "standin.cli:main"
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["standin"]
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = ["standin", "tests", "README.md", "LICENSE", "ARCHITECTURE.md", "CHANGELOG.md"]
51
+
52
+ [tool.pytest.ini_options]
53
+ pythonpath = ["."]
54
+ testpaths = ["tests"]
55
+
56
+ [tool.ruff]
57
+ line-length = 100
58
+ target-version = "py39"
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "UP", "B", "C4"]
62
+ ignore = ["E501"]
63
+
64
+ [tool.mypy]
65
+ python_version = "3.10"
66
+ ignore_missing_imports = true
67
+ warn_redundant_casts = true
68
+ no_implicit_optional = true
@@ -0,0 +1,42 @@
1
+ """standin — a stand-in for the real LLM in your tests.
2
+
3
+ Record real LLM API calls once, then replay them forever: fast, free, offline,
4
+ and deterministic. Provider-agnostic (hooks httpx), streaming and tool-calls
5
+ supported, secrets redacted so cassettes are safe to commit.
6
+
7
+ import standin
8
+
9
+ with standin.use_cassette("tests/cassettes/summary.json"):
10
+ resp = openai_client.chat.completions.create(...) # recorded once, replayed after
11
+
12
+ Architecture (see ARCHITECTURE.md): a transport-neutral policy **engine** sits
13
+ behind pluggable **interceptors** (httpx today), **matchers**, **redactors**,
14
+ and **stores**, so behavior is easy to reason about and extend.
15
+ """
16
+ from .config import Config
17
+ from .core import use_cassette
18
+ from .exceptions import CannotReplay, CassetteError, ConfigError, StandinError
19
+ from .matching import DefaultMatcher, FuzzyMatcher, Matcher
20
+ from .models import Mode
21
+ from .redaction import DefaultRedactor, NullRedactor, Redactor
22
+ from .storage import CassetteStore, JSONCassetteStore
23
+
24
+ __version__ = "0.2.0"
25
+ __all__ = [
26
+ "use_cassette",
27
+ "Config",
28
+ "Mode",
29
+ "StandinError",
30
+ "CannotReplay",
31
+ "CassetteError",
32
+ "ConfigError",
33
+ "Redactor",
34
+ "DefaultRedactor",
35
+ "NullRedactor",
36
+ "Matcher",
37
+ "DefaultMatcher",
38
+ "FuzzyMatcher",
39
+ "CassetteStore",
40
+ "JSONCassetteStore",
41
+ "__version__",
42
+ ]