Skip to content

RESPX

codecov PyPi Version Python Versions

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


QuickStart

Start by mocking out HTTPX and/or HTTP Core, using respx.mock, and then add desired request patterns to mock your responses.

import httpx
import respx


@respx.mock
def test_something():
    request = respx.post("https://foo.bar/baz/", status_code=201)
    response = httpx.post("https://foo.bar/baz/")
    assert request.called
    assert response.status_code == 201

Usage

The QuickStart section covers the basics. Continue reading in detail on how Mocking HTTPX is done, or head over to the Developer Interface for a complete guide on how to mock your responses.

Tip

You can use RESPX not only to mock out HTTPX, but to actually mock responses for any library using HTTP Core.

Installation

Install with pip:

$ pip install respx

Requires Python 3.6+ and HTTPX 0.14.0+. See Changelog for older HTTPX compatibility.