Python BSD-3-Clause

respx

Mock HTTPX with awesome request patterns and response side effects 🦋

L

lundberg

Dernière activité 21 juil. 2026
lundberg/respx

836

étoiles

64

forks

29

issues ouvertes

httpxmockpytesttesting

Ce README est souvent en anglais.

RESPX

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


tests codecov PyPi Version PyPI Downloads Python Versions

Documentation

Full documentation is available at lundberg.github.io/respx

QuickStart

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


@respx.mock
def test_example():
    my_route = respx.get("https://example.org/").mock(return_value=Response(204))
    response = httpx.get("https://example.org/")
    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):
    respx_mock.get("https://foo.bar/").mock(return_value=httpx.Response(204))
    response = httpx.get("https://foo.bar/")
    assert response.status_code == 204


@pytest.mark.respx(base_url="https://foo.bar")
def test_with_marker(respx_mock):
    respx_mock.get("/baz/").mock(return_value=httpx.Response(204))
    response = httpx.get("https://foo.bar/baz/")
    assert response.status_code == 204

Installation

Install with pip:

$ pip install respx

Requires Python 3.8+ and HTTPX 0.25+. See Changelog for older HTTPX compatibility.

Projets similaires

pytest fixture to mock HTTPX

Pythonhacktoberfesthttphttpx
CColin-b
455 étoiles43

Aioresponses is a helper for mock/fake web requests in python aiohttp package.

Pythonaiohttpasynciomocking
Ppnuckowski
557 étoiles104

Automatically mock your HTTP interactions to simplify and speed up testing

Pythonhttpmockingpython
Kkevin1024
3 k étoiles442