Skip to main content

A utility for mocking out the Python HTTPX and HTTP Core libraries.

Project description


RESPX - Mock HTTPX with awesome request patterns and response side effects.

tests codecov PyPi Version Python Versions


Full documentation is available at


RESPX is a simple, yet powerful, utility for mocking out the HTTPX, and HTTP Core, libraries.

Start by patching HTTPX, using respx.mock, then add request routes to mock responses.

import httpx
import respx

from httpx import Response

def test_example():
    my_route = respx.get("").mock(return_value=Response(204))
    response = httpx.get("")
    assert my_route.called
    assert response.status_code == 204

Read the User Guide for a complete walk-through.

pytest + httpx

For a neater pytest experience, RESPX includes a respx_mock fixture for easy HTTPX mocking, along with an optional respx marker to fine-tune the mock settings.

import httpx
import pytest

def test_default(respx_mock):
    response = httpx.get("")
    assert response.status_code == 204

def test_with_marker(respx_mock):
    response = httpx.get("")
    assert response.status_code == 204


Install with pip:

$ pip install respx

Requires Python 3.7+ and HTTPX 0.21+. See Changelog for older HTTPX compatibility.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respx-0.20.2.tar.gz (26.1 kB view hashes)

Uploaded source

Built Distribution

respx-0.20.2-py2.py3-none-any.whl (22.8 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page