pytest-httpx
Send responses to httpx.
Decision gist · record as of 2026-08-14
Yes. pytest-httpx is actively maintained, has no known vulnerabilities, minimal install friction, and a permissive MIT license. It's a focused, well-scoped tool for a common testing need (mocking httpx requests). Install it if you test code that uses httpx; skip it only if you don't use httpx or prefer a different mocking approach.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction: pure Python wheel with only two runtime dependencies (httpx and pytest).
- Actively maintained with recent commits; last release 127 days ago.
License · maintenance · safety
permissive license (permissive) — MIT License permits unrestricted use, modification, and distribution with only attribution required—no restrictions on commercial or proprietary use.
last release 2026-04-09 (127 days) · last repo commit 2026-08-13 · 454 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 22,873,380 downloads/mo, #964 on PyPI
Alternatives
Verify before relying
pip install pytest-httpx
import httpx
from pytest_httpx import HTTPXMock
def test_example(httpx_mock: HTTPXMock):
httpx_mock.add_response(url="https://example.com", method="GET")
with httpx.Client() as client:
response = client.get("https://example.com")
assert response.status_code == 200- Whether the package's stated stability claim ('current state can be considered as stable') aligns with its pre-1.0.0 version number and actual production use.
- Performance characteristics when mocking large numbers of responses or complex request matching patterns.
What it is and what it does
pytest-httpx is a pytest plugin that mocks httpx HTTP requests by intercepting them and returning pre-configured responses. It works as a fixture you inject into test functions, allowing you to define mock responses for specific URLs, HTTP methods, headers, query parameters, and request bodies. The package supports both synchronous httpx.Client and asynchronous httpx.AsyncClient, making it suitable for testing code that uses either pattern.
The fixture validates that all registered responses were actually used during the test (unless configured otherwise), helping catch cases where your code doesn't make the expected requests. You can match responses based on URL patterns (exact strings, regex, or httpx.URL objects), HTTP method, query parameters, headers, request body, and proxy URLs. It also supports dynamic responses, exception raising, and configuration options to relax strict matching when needed.
Use it for
- Unit test code that calls external HTTP APIs without making real network requests.
- Test both sync and async httpx clients with the same mock fixture setup.
- Verify that your code sends requests with correct headers, query parameters, and request bodies.
- Test error handling by mocking responses with non-200 status codes or raising exceptions.
- Validate that all expected HTTP requests are made during test execution.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
pytest-httpx is actively maintained, has no known vulnerabilities, minimal install friction, and a permissive MIT license. It's a focused, well-scoped tool for a common testing need (mocking httpx requests). Install it if you test code that uses httpx; skip it only if you don't use httpx or prefer a different mocking approach.
Install
pytest-httpx on PyPI
Before you install
Low friction: pure Python wheel with only two runtime dependencies (httpx and pytest). Actively maintained with recent commits; last release 127 days ago.
Requires Python 3.10 or later.
License in practice
MIT License permits unrestricted use, modification, and distribution with only attribution required—no restrictions on commercial or proprietary use.
Quickstart
pip install pytest-httpx
import httpx
from pytest_httpx import HTTPXMock
def test_example(httpx_mock: HTTPXMock):
httpx_mock.add_response(url="https://example.com", method="GET")
with httpx.Client() as client:
response = client.get("https://example.com")
assert response.status_code == 200
Verify before relying
- Whether the package's stated stability claim ('current state can be considered as stable') aligns with its pre-1.0.0 version number and actual production use.
- Performance characteristics when mocking large numbers of responses or complex request matching patterns.
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packageshttpxpytest |
| Maintenance | Actively maintained 127 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 22,873,380 / month, #964 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Internet :: WWW/HTTPTopic :: Software Development :: Build ToolsTyping :: Typed |
Evidence: pytest_httpx-0.36.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytest httpx fixture”
- pytest-httpxpytest-httpx provides a pytest fixture that intercepts httpx requests…
- respxRESPX mocks HTTPX and HTTP Core libraries for testing, letting you…
- pytest-lazy-fixturesAllows you to reference pytest fixtures directly within…
Give your agent the search over MCP, or paste the wish link into any chat.
More WWW/HTTP packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
h11 is a pure-Python HTTP/1.1 protocol implementation that handles parsing and serializing HTTP messages without any built-in I/O, letting you integrate it with any network layer you choose.
HTTPX is a fully featured HTTP client library for Python that provides both sync and async APIs, with support for HTTP/1.1 and HTTP/2, plus an integrated command-line client.
Install it if you are building new projects or modernizing existing ones that rely on HTTP.
A minimal low-level HTTP client library that sends HTTP requests with thread-safe and task-safe connection pooling, supporting HTTP/1.1, HTTP/2, proxies, and both sync and async interfaces.
aiohttp is an async HTTP client and server framework built on asyncio, supporting both WebSockets and middleware-based routing for building concurrent web applications.
Install it if you need async HTTP client or server capabilities in asyncio-based applications.
See also respx · pytest-httpbin · opentelemetry-instrumentation-httpx · pytest-mock · aresponses · httpx-socks · aiointercept · zyte-api · pook