{"id":24032,"library":"mgzip","title":"mgzip","description":"A multi-threading implementation of Python's gzip module, providing drop-in replacements for gzip.open, gzip.compress, and gzip.decompress with parallel compression/decompression. Current version 0.2.5 supports Python 3.8-3.14. Active development with regular releases.","status":"active","version":"0.2.5","language":"python","source_language":"en","source_url":"https://github.com/vinlyx/mgzip","tags":["gzip","multithreading","parallel","compression","decompression"],"install":[{"cmd":"pip install mgzip","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Using gzip.open instead of mgzip.open won't use multithreading.","wrong":"import gzip (then using gzip.open)","symbol":"open","correct":"from mgzip import open"},{"note":"","wrong":"","symbol":"compress","correct":"from mgzip import compress"},{"note":"","wrong":"","symbol":"decompress","correct":"from mgzip import decompress"}],"quickstart":{"code":"from mgzip import open\n\n# Multithreaded gzip compression\nwith open('example.txt.gz', 'wt', compresslevel=5, thread=4) as f:\n    f.write('Hello, world!')\n\n# Multithreaded decompression\nwith open('example.txt.gz', 'rt', thread=4) as f:\n    print(f.read())","lang":"python","description":"Basic usage of mgzip.open for writing and reading gzip files with multiple threads."},"warnings":[{"fix":"Use keyword argument 'thread' when opening files.","message":"The parameter for number of threads is 'thread' (singular), not 'threads' or 'num_workers'.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using standard gzip for files < 1 MB.","message":"mgzip may be slower than gzip for small files or low block counts due to threading overhead.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace 'MultiGzipFile' with mgzip.open() or mgzip.MultiGzipFile is still available but not recommended.","message":"The old class name 'MultiGzipFile' is deprecated; use 'open' function instead.","severity":"deprecated","affected_versions":">=0.2.1"},{"fix":"Upgrade to mgzip >=0.2.3.","message":"Python 3.12+ removed some internal attributes (e.g., _read_exact, unconsumed_tail); mgzip 0.2.3+ fixed this, but older versions break on Python 3.12+.","severity":"breaking","affected_versions":"<0.2.3"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade mgzip to >=0.2.3.","cause":"Python 3.12+ removed internal gzip._read_exact method.","error":"AttributeError: '_MultiGzipReader' object has no attribute '_read_exact'"},{"fix":"Upgrade mgzip to >=0.2.3.","cause":"Python 3.12+ changed zlib decompressobj API.","error":"AttributeError: 'Decompress' object has no attribute 'unconsumed_tail'"},{"fix":"Upgrade mgzip to >=0.2.2.","cause":"Multiprocessing pool not cleaned properly in mgzip <0.2.2.","error":"ResourceWarning: unclosed <socket> for multiprocessing pool"},{"fix":"Use thread=<N> as keyword argument.","cause":"Using 'threads' or 'num_threads' instead of 'thread'.","error":"TypeError: 'thread' is an invalid keyword argument for this function"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}