packaging-legacy
Support for legacy Python packaging APIs removed from packaging.
Repository Health
Technical Analysis
packaging-legacy is a small Python library that preserves “legacy” packaging functionality that has been deprecated and removed from the upstream pypa/packaging library. Its centerpiece is LegacyVersion and a version.parse function that can handle version strings which are not valid PEP 440 versions.
When pypa/packaging removed LegacyVersion, tools that still needed to parse and compare old, non-conformant version strings lost that capability. packaging-legacy fills the gap with a drop-in replacement — you simply import parse and LegacyVersion from packaging_legacy.version instead — so package indexes, mirrors, and analysis tools can keep working with historical releases.
What You Get
- A LegacyVersion class compatible with packaging’s version object model
- A parse function that returns a Version for PEP 440 strings or a LegacyVersion otherwise
- A drop-in import path to replace the removed packaging.version.LegacyVersion
- Full type annotations with a py.typed marker
Common Use Cases
- Parsing and comparing historical, non-PEP 440 package version strings
- Maintaining package index or mirror tooling that must handle legacy releases
- Migrating code that depended on packaging.version.LegacyVersion after its removal
Under The Hood
Architecture - The whole library is a single module, packaging_legacy/version.py. It imports the current packaging.version internals (_BaseVersion, InvalidVersion, and the standard parse) and defines a parse wrapper that delegates to the PEP 440 parser, catching InvalidVersion to construct a LegacyVersion instead. LegacyVersion subclasses _BaseVersion and builds a comparison key via a _legacy_cmpkey routine so legacy versions remain orderable.
Tech Stack - Pure Python built with a modern pyproject.toml. Its only real dependency is the upstream packaging library, whose base classes it extends. nox is used for task automation.
Code Quality - The code is fully typed with a py.typed marker and kept intentionally minimal. A tests/ directory exercises the parsing and comparison behavior, mirroring the semantics of the code that was removed upstream to ensure faithful compatibility.
API Design - The API is a deliberate one-to-one mirror of the removed upstream surface: the same parse and LegacyVersion names in a version module, so adoption is a single import-path change. This makes the learning curve near-zero for anyone who used the original packaging.version APIs.