aiohttp-zlib-ng

raw JSON →
0.3.2 verified Fri May 01 auth: no python

A library to enable zlib_ng (and optionally isal) for aiohttp, providing faster compression/decompression. Current version 0.3.2, requires Python >=3.8, <4.0. Maintained by bdraco, release cadence is sporadic.

pip install aiohttp-zlib-ng
error ModuleNotFoundError: No module named 'aiohttp_zlib_ng'
cause Library not installed or used incorrect import (note underscore not hyphen).
fix
Install: pip install aiohttp-zlib-ng, then import: from aiohttp_zlib_ng import install_zlib_ng
error AttributeError: module 'aiohttp_zlib_ng' has no attribute 'install'
cause Wrong function name; correct name is install_zlib_ng.
fix
Use: from aiohttp_zlib_ng import install_zlib_ng
breaking v0.3.0 made isal optional; previously isal was required. To use isal, install with aiohttp-zlib-ng[isal].
fix Install extra: pip install aiohttp-zlib-ng[isal]
gotcha install_zlib_ng() must be called before creating any aiohttp session; otherwise compression will not be patched.
fix Call install_zlib_ng() at import time or at the very beginning of your application.
gotcha zlib_ng may not be available on all platforms (e.g., missing AVX instructions). The library silently falls back to standard zlib; check logs for warnings.
fix Verify installation: try installing with pip install aiohttp-zlib-ng and test on target platform.

Import and call install_zlib_ng() to enable zlib_ng support in aiohttp. Ensure aiohttp is installed.

import aiohttp
from aiohttp_zlib_ng import install_zlib_ng

install_zlib_ng()

async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://httpbin.org/get') as resp:
            print(resp.status)