{"id":6965,"library":"aiohttp-fast-zlib","title":"aiohttp-fast-zlib","description":"aiohttp-fast-zlib is a Python library (current version 0.3.0) that replaces the default `zlib` usage in `aiohttp` with faster alternatives like `isal` or `zlib-ng`. This significantly improves compression and decompression performance, especially for `aiohttp`'s WebSocket connections, where `zlib` can be a bottleneck. The library has seen several updates over the past year, indicating active maintenance and development.","status":"active","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/bluetooth-devices/aiohttp-fast-zlib","tags":["aiohttp","zlib","compression","performance","async","networking","websockets"],"install":[{"cmd":"pip install aiohttp-fast-zlib","lang":"bash","label":"Base installation"},{"cmd":"pip install aiohttp-fast-zlib[isal]","lang":"bash","label":"With isal for maximum speed"},{"cmd":"pip install aiohttp-fast-zlib[zlib-ng]","lang":"bash","label":"With zlib-ng as an alternative fast backend"}],"dependencies":[{"reason":"Core dependency for asynchronous HTTP client/server functionality. Version 0.3.0 requires aiohttp>=3.12.0.","package":"aiohttp","optional":false},{"reason":"Optional dependency to enable the highly optimized ISA-L compression library. Recommended for best performance.","package":"python-isal","optional":true},{"reason":"Optional dependency to enable the zlib-ng compression library, another fast alternative.","package":"python-zlib-ng","optional":true}],"imports":[{"note":"Call `enable()` once at application startup to patch aiohttp's zlib backend.","symbol":"enable","correct":"import aiohttp_zlib_fast\naiohttp_zlib_fast.enable()"}],"quickstart":{"code":"import aiohttp\nimport asyncio\nimport os\nimport aiohttp_zlib_fast\n\n# Enable the fast zlib backend. isal is preferred if available, then zlib-ng, else standard zlib.\naiohttp_zlib_fast.enable()\n\nasync def fetch(session, url):\n    async with session.get(url) as response:\n        print(f\"Status: {response.status}\")\n        print(f\"Content-type: {response.headers.get('content-type')}\")\n        # If the response is compressed, aiohttp will decompress it using the enabled backend\n        text = await response.text()\n        print(f\"Body snippet: {text[:100]}...\")\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        # Use a real URL, or an httpbin-like service that supports compression\n        await fetch(session, os.environ.get('TEST_URL', 'http://httpbin.org/gzip'))\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to enable `aiohttp-fast-zlib` and then use a standard `aiohttp.ClientSession` to make a request. The `enable()` call patches `aiohttp` globally to use the faster zlib backend. You can set the `TEST_URL` environment variable to point to a service that returns gzipped content (e.g., `httpbin.org/gzip`) to observe its effect."},"warnings":[{"fix":"Install with an extra: `pip install aiohttp-fast-zlib[isal]` or `pip install aiohttp-fast-zlib[zlib-ng]`.","message":"Performance will be degraded if neither 'isal' nor 'zlib-ng' are installed alongside 'aiohttp-fast-zlib'. The library will silently fall back to the slower standard Python 'zlib' module.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your `aiohttp` version meets the requirements of `aiohttp-fast-zlib`. For v0.3.0, ensure `aiohttp>=3.12.0` is installed. If using an older `aiohttp-fast-zlib`, you may need an older `aiohttp`.","message":"aiohttp-fast-zlib v0.3.0 introduces support for aiohttp 3.12 and newer. Older versions of aiohttp-fast-zlib had different aiohttp compatibility requirements. Always check the project's PyPI or GitHub page for precise aiohttp version compatibility with the specific aiohttp-fast-zlib version you are using.","severity":"breaking","affected_versions":">=0.3.0 (specifically related to aiohttp version changes)"},{"fix":"If using `aiohttp-fast-zlib`, rely on its `enable()` function for automatic backend selection. Avoid `aiohttp.set_zlib_backend()` unless you explicitly want to manage the zlib backend yourself and override `aiohttp-fast-zlib`'s behavior.","message":"Aiohttp itself (>=3.12) provides `aiohttp.set_zlib_backend()` for manually specifying a zlib-compatible module. `aiohttp-fast-zlib` offers automatic detection and fallback, but direct `aiohttp.set_zlib_backend()` calls will override its effects.","severity":"gotcha","affected_versions":"aiohttp-fast-zlib all versions with aiohttp >=3.12"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install `aiohttp-fast-zlib` with the desired extra: `pip install aiohttp-fast-zlib[isal]` (recommended) or `pip install aiohttp-fast-zlib[zlib-ng]`.","cause":"The optional faster compression libraries (`isal` or `zlib-ng`) were not installed when `aiohttp-fast-zlib` was installed.","error":"WARNING (MainThread) [aiohttp_fast_zlib] zlib_ng and isal are not available, falling back to zlib, performance will be degraded."},{"fix":"Carefully check the `aiohttp` version required by all libraries in your project. Attempt to find an `aiohttp` version that satisfies all dependencies, or isolate conflicting dependencies using virtual environments.","cause":"Conflicting `aiohttp` version requirements between `aiohttp-fast-zlib` and other installed libraries in your environment.","error":"ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts: <another_library> requires aiohttp==X.Y.Z, but you have aiohttp A.B.C which is incompatible."}]}