Starting with Python 3.14, PEP 784 introduces a new compression namespace that provides canonical import names for compression
modules. The new imports like compression.lzma, compression.bz2, compression.gzip, and
compression.zlib are now the preferred way to import these modules.
Using the legacy top-level module names is still supported for backwards compatibility, but the new namespace imports offer several advantages:
- They provide a unified interface for all compression-related functionality
- They follow Python’s evolving standard library organization
- They prevent potential name collisions with third-party packages
While the legacy imports continue to work, adopting the new canonical names helps keep your code aligned with Python’s current best practices and
prepares it for future developments in the standard library.
What is the potential impact?
Using legacy compression imports does not cause functional issues, but it means your code is not following the current Python standards. This can
make the codebase appear outdated and may require updates in the future if the legacy imports are eventually deprecated.
How to fix?
Replace legacy compression module imports with the new compression namespace imports. Update all import statements to use the canonical names
introduced in Python 3.14.
Non-compliant code example
from lzma import LZMAFile
from bz2 import BZ2File
from gzip import GzipFile
from zlib import compress
Compliant code example
from compression.lzma import LZMAFile
from compression.bz2 import BZ2File
from compression.gzip import GzipFile
from compression.zlib import compress
Documentation