Offline replay

stubsmith.replay() answers your code's outbound HTTP calls from recordings. It intercepts requests and, from Python SDK 0.9.0, httpx (Client and AsyncClient); calls made through other libraries are not intercepted and attempt real network connections. Inside the block nothing sent through requests or httpx reaches the network and the dependency does not need to be running, so a test suite needs no API key once the bundle is on disk. A response captured through httpx client.stream() is stored without a body, so it replays with an empty body. Upgrading from 0.8: httpx calls inside replay() now get a recorded answer or StubNotFound instead of reaching the real service.

import stubsmith

def test_charge_is_declined():
    with stubsmith.replay():
        with pytest.raises(CardDeclined):
            PaymentClient().charge(amount_cents=950_000, currency="USD")
import { test } from "node:test";
import assert from "node:assert/strict";
import { replay } from "stubsmith";

test("charge is declined", async () => {
  const r = replay();
  try {
    await assert.rejects(
      new PaymentClient().charge({ amountCents: 950_000, currency: "USD" }),
      CardDeclined,
    );
  } finally {
    r.restore();
  }
});

On Node 24 you can write using r = replay(); instead of try/finally; it restores at the end of the block.

The bundle is found without configuration: an explicit path or dict, then $STUBSMITH_BUNDLE, then an upward search for .stubsmith/bundle.json. A request that matches no recording raises StubNotFound with a diff against the closest one; it never falls through to the network.