--- id: requests-mock version: "1.12.1" license: Apache-2 license_treatment: permissive maintenance: dormant --- # requests-mock — Mock out responses from the requests package License: permissive · Maintenance: dormant · Popularity: top 1,000 on PyPI ## Install pip install requests-mock uv add requests-mock poetry add requests-mock ## Description =============================== requests-mock =============================== .. image:: https://badge.fury.io/py/requests-mock.png :target: https://pypi.org/project/requests-mock/ Intro ===== `requests-mock` provides a building block to stub out the HTTP `requests`_ portions of your testing code. You should checkout the `docs`_ for more information. The Basics ========== Everything in `requests`_ eventually goes through an adapter to do the transport work. `requests-mock` creates a custom `adapter` that allows you to predefine responses when certain URIs are called. There are then a number of methods provided to get the adapter used. A simple example: .. code:: python >>> import requests >>> import requests_mock >>> session = requests.Session() >>> adapter = requests_mock.Adapter() >>> session.mount('mock://', adapter) >>> adapter.register_uri('GET', 'mock://test.com', text='data') >>> resp = session.get('mock://test.com') >>> resp.status_code, resp.text (200, 'data') Obviously having all URLs be `mock://` prefixed isn't going to be useful, so you can use `requests_mock.Mocker` to get the adapter into place. As a context... ## AI interpretation — verify before relying requests-mock stubs HTTP responses from the requests library during testing by intercepting calls through a custom adapter, letting you predefine mock responses for specific URIs. Verdict: Stable, low-friction testing utility for mocking requests library calls. Dormant maintenance (867 days since last release) poses minimal risk given its narrow, well-defined scope and zero known vulnerabilities. Suitable for projects that need reliable HTTP mocking without active development pressure. [View on SkillFed](https://skillfed.io/packages/requests-mock) · [View on PyPI](https://pypi.org/project/requests-mock/)