API Reference

respx

A utility for mocking HTTPX requests in tests, supporting routes, patterns, and assertions.

Official Documentation ↗
CompatibilityThis documentation covers version v0.21. Check the official docs for the latest API surface.

Installation

pippip install respx

Methods

respx patches HTTPX transports so requests return mocked responses without a network.

Key Features

  • Route-based HTTPX mocking
  • Side effects and response sequences
  • Call assertions and pass-through

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T17:50:10+08:00 via WebFetch https://raw.githubusercontent.com/lundberg/respx/master/docs/api.md.

FAQ

Why is a real request going out?
A URL not matched by any route is passed through by default; set assert_all_called and explicit routes so gaps are visible.
How do I return different responses over time?
Use side_effect with a list or callable so successive calls return a sequence.
Does it work with other clients?
No. respx targets HTTPX. Use responses for requests or a similar tool for other libraries.