{"id":1777,"library":"vcrpy","title":"vcrpy","description":"vcrpy (version 8.1.1) is a Python library that automatically mocks your HTTP interactions, making tests faster and more reliable by 'recording' network requests and 'replaying' them from a local file (a 'cassette'). It supports various HTTP libraries like `requests`, `aiohttp`, and `httpx`. The library maintains an active development pace with frequent updates and bug fixes, typically releasing new versions every few months.","status":"active","version":"8.1.1","language":"en","source_language":"en","source_url":"https://github.com/kevin1024/vcrpy","tags":["http","mocking","testing","cassette","network","api","requests","aiohttp","httpx"],"install":[{"cmd":"pip install vcrpy","lang":"bash","label":"Install core library"},{"cmd":"pip install vcrpy[requests,aiohttp,httpx]","lang":"bash","label":"Install with common HTTP client integrations"}],"dependencies":[{"reason":"Requires Python 3.10 or newer since v8.0.0.","package":"python","optional":false},{"reason":"Requires urllib3 version 2 or newer since v8.0.0.","package":"urllib3","optional":false}],"imports":[{"note":"The primary module is `vcr`, not `vcrpy`.","wrong":"from vcrpy import VCR","symbol":"VCR","correct":"from vcr import VCR"},{"note":"Commonly used directly as a decorator or context manager from the imported `vcr` module.","symbol":"use_cassette","correct":"import vcr\n\n@vcr.use_cassette('cassettes/my_cassette.yaml')"}],"quickstart":{"code":"import vcr\nimport requests\n\ndef fetch_data():\n    # Simulate an external API call\n    response = requests.get('http://worldtimeapi.org/api/timezone/America/New_York')\n    response.raise_for_status()\n    return response.json()\n\n# Configure VCR to store cassettes in a specific directory\nmy_vcr = vcr.VCR(cassette_library_dir='fixtures/vcr_cassettes')\n\n# Use VCR as a context manager to record/replay HTTP interactions\nwith my_vcr.use_cassette('timezone_ny.yaml'):\n    print(\"Fetching data with VCR...\")\n    data = fetch_data()\n    print(f\"Current time: {data['datetime']}\")\n\n# The next time this runs, it will use the recorded cassette if present.\nprint(\"Fetching data again (should be from cassette if run previously)...\")\nwith my_vcr.use_cassette('timezone_ny.yaml'):\n    data = fetch_data()\n    print(f\"Replayed time: {data['datetime']}\")\n\n# Example of clearing a created directory for clean runs (optional)\nimport os\nimport shutil\nif os.path.exists('fixtures'):\n    print(\"Cleaning up 'fixtures' directory.\")\n    shutil.rmtree('fixtures')","lang":"python","description":"This quickstart demonstrates how to use `vcrpy` as a context manager with `requests` to record and replay HTTP interactions. The `vcr.VCR()` object is configured to store cassettes in a specified directory. The first run will make a real network request and save it; subsequent runs with the same cassette name will replay the recorded response, speeding up tests and isolating them from network fluctuations."},"warnings":[{"fix":"Upgrade Python to version 3.10 or newer.","message":"vcrpy v8.0.0 dropped support for Python versions older than 3.10. Users on Python 3.9 or earlier will need to upgrade their Python environment.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Ensure `urllib3` is updated to version 2.0.0 or newer (e.g., `pip install 'urllib3>=2'`).","message":"vcrpy v8.0.0 dropped support for `urllib3` versions older than 2.0.0. This can cause compatibility issues if your project relies on an older `urllib3` version.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Recreate any `httpx` related cassettes after upgrading. Review `httpx` request patterns if encountering new issues.","message":"The `httpx` integration was significantly rewritten in v8.0.0 to patch `httpcore` directly. This change may require recreation of existing `httpx` cassettes and resolves issues like `httpx.ResponseNotRead` exceptions.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"If your project uses `boto`, migrate to `boto3` or pin `vcrpy` to a version older than 6.0.0.","message":"vcrpy v6.0.0 dropped support for the deprecated `boto` library. `boto3` remains fully supported.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"After upgrading to v6.0.0 or later, it is recommended to recreate all existing `httpx` cassettes.","message":"Cassettes recorded for `httpx` interactions in versions prior to v6.0.0 might be corrupted or incorrectly saved due to a binary format issue fix.","severity":"gotcha","affected_versions":"<6.0.0"},{"fix":"Upgrade to v8.1.1 or newer to ensure correct behavior of sync requests in async contexts with `httpx`.","message":"Prior to v8.1.1, there were issues with handling synchronous HTTP requests (especially with `httpx`) when executed within an asynchronous context.","severity":"gotcha","affected_versions":"<8.1.1"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}