{"id":574,"library":"responses","title":"responses","description":"responses is a utility library designed for mocking out the `requests` Python library, making it easier to test code that performs HTTP requests. It allows developers to register mock responses for specific URLs and HTTP methods, controlling the behavior of `requests` during testing. The library is actively maintained, with frequent releases, and is currently at version 0.26.0.","status":"active","version":"0.26.0","language":"python","source_language":"en","source_url":"https://github.com/getsentry/responses","tags":["testing","mocking","requests","http"],"install":[{"cmd":"pip install responses","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This library mocks 'requests', so 'requests' is a required peer dependency for functionality.","package":"requests","optional":false}],"imports":[{"symbol":"responses","correct":"import responses"},{"note":"Commonly used as a decorator: `@responses.activate`","symbol":"activate","correct":"from responses import activate"},{"note":"Used for advanced request body or header matching.","symbol":"matchers","correct":"from responses import matchers"}],"quickstart":{"code":"import requests\nimport responses\n\n@responses.activate\ndef test_example_request():\n    responses.add(\n        responses.GET,\n        'http://example.com/api/test',\n        json={'message': 'Hello, World!'},\n        status=200,\n        content_type='application/json'\n    )\n\n    # This request will be intercepted by 'responses'\n    resp = requests.get('http://example.com/api/test')\n\n    assert resp.status_code == 200\n    assert resp.json() == {'message': 'Hello, World!'}\n\n    # Verify that exactly one request was made to the registered URL\n    assert len(responses.calls) == 1\n    assert responses.calls[0].request.url == 'http://example.com/api/test'\n\nprint(\"Running test_example_request...\")\ntest_example_request()\nprint(\"Test completed successfully.\")","lang":"python","description":"The quickstart demonstrates mocking a GET request using the `@responses.activate` decorator and `responses.add()` method. It sets up a mock response with a JSON body and then makes a `requests.get()` call, which is intercepted by `responses`. Finally, it asserts the response content and verifies that the mock was called."},"warnings":[{"fix":"Review tests that might rely on exceptions suppressing `responses` assertions. Adjust tests to explicitly handle the assertion failure, or set `assert_all_requests_are_fired=False` if this validation is not needed.","message":"In version 0.26.0, the behavior of `assert_all_requests_are_fired=True` (the default when using `responses.activate` as a context manager or decorator) changed. Assertions about unfired requests are now raised even if an exception occurs within the context manager or decorated function. Previously, these assertions were suppressed, which could hide uncalled mocks.","severity":"breaking","affected_versions":"0.26.0 and later"},{"fix":"Use the attributes via `responses.mock`, such as `responses.mock.assert_all_requests_are_fired`, `responses.mock.passthru_prefixes`, and `responses.mock.target` instead.","message":"Direct access to `assert_all_requests_are_fired`, `passthru_prefixes`, and `target` from the top-level `responses` module (e.g., `responses.assert_all_requests_are_fired`) is deprecated.","severity":"deprecated","affected_versions":"0.20.0 and later"},{"fix":"For matching query parameters, use `responses.matchers.query_param_matcher` for dictionary-based matching or `responses.matchers.query_string_matcher` for matching the raw query string.","message":"The `match_querystring` argument in `Response` and `CallbackResponse` is deprecated.","severity":"deprecated","affected_versions":"Pre-0.17.0, still present but discouraged"},{"fix":"For URLs expected to be called multiple times, set `repeat=True` in `responses.add()` (e.g., `responses.add(..., repeat=True)`), or add multiple `responses.add()` calls for each expected interaction.","message":"By default, `responses.add` assumes a mock should be consumed once. If `assert_all_requests_are_fired=True` (the default) is active, calling the same URL multiple times with a single `responses.add` definition will cause an `AssertionError` after the first call.","severity":"gotcha","affected_versions":"All versions with `assert_all_requests_are_fired` enabled"},{"fix":"Upgrade to `responses` 0.25.0 or later to ensure `matchers.header_matcher` properly validates the presence of matched headers.","message":"Prior to version 0.25.0, `matchers.header_matcher` did not correctly fail if a header specified in the matcher was entirely missing from the request; it only validated the value of present headers.","severity":"gotcha","affected_versions":"Prior to 0.25.0"},{"fix":"Ensure `responses.activate`'s scope is properly managed and isolated to avoid interference. If possible, avoid combining multiple patching libraries for the same underlying network functionality in a single test, or use `responses.mock.passthru_all` or `responses.add_passthru` to allow specific real requests.","message":"When using `responses` alongside other network mocking libraries (e.g., `httpretty`, `moto`) or attempting to make actual network calls within the same test context, conflicts can arise as `responses` extensively patches the `requests` library.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T16:14:16.164Z","next_check":"2026-06-26T00:00:00.000Z","problems":[],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"0.26.0","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.85,"mem_mb":17.1,"disk_size":"23.5M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.88,"mem_mb":16.9,"disk_size":"23.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.2,"import_time_s":0.52,"mem_mb":17.1,"disk_size":"25M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.58,"mem_mb":16.9,"disk_size":"25M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.22,"mem_mb":18.8,"disk_size":"25.8M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.3,"mem_mb":18.7,"disk_size":"25.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.3,"import_time_s":1,"mem_mb":18.8,"disk_size":"27M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.97,"mem_mb":18.7,"disk_size":"27M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.25,"mem_mb":18.7,"disk_size":"17.6M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.34,"mem_mb":18.7,"disk_size":"17.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.1,"import_time_s":1.24,"mem_mb":18.7,"disk_size":"19M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.2,"mem_mb":18.7,"disk_size":"19M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.28,"mem_mb":19.5,"disk_size":"17.4M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.34,"mem_mb":19.7,"disk_size":"17.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.1,"import_time_s":1.16,"mem_mb":19.4,"disk_size":"19M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.26,"mem_mb":19.4,"disk_size":"18M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.74,"mem_mb":16.4,"disk_size":"22.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.8,"mem_mb":16.5,"disk_size":"22.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.6,"import_time_s":0.69,"mem_mb":16.4,"disk_size":"24M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.65,"mem_mb":16.5,"disk_size":"24M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}