{"id":7487,"library":"packaging-legacy","title":"Packaging Legacy","description":"Packaging-legacy is a Python library, currently at version 23.0.post0, that provides support for 'legacy' Python packaging functionality. It restores features, primarily related to version parsing, that were removed from the official `packaging` library. Its main utility is the `packaging_legacy.version.parse` function, which can handle version strings that the modern `packaging` library would deem invalid. The library has an infrequent release cadence, with only two releases to date, both in late 2023.","status":"active","version":"23.0.post0","language":"en","source_language":"en","source_url":"https://github.com/di/packaging_legacy","tags":["packaging","legacy","versioning","pypa","compatibility"],"install":[{"cmd":"pip install packaging-legacy","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Use 'packaging_legacy' for parsing older, non-PEP 440 compliant version strings that the modern 'packaging' library rejects. The original 'packaging.version.parse' no longer returns 'LegacyVersion' for invalid inputs.","wrong":"from packaging.version import parse","symbol":"parse","correct":"from packaging_legacy.version import parse"},{"note":"'LegacyVersion' was removed from the 'packaging' library in version 22.0. This import is specifically for interacting with that legacy type.","wrong":"from packaging.version import LegacyVersion","symbol":"LegacyVersion","correct":"from packaging_legacy.version import LegacyVersion"}],"quickstart":{"code":"from packaging_legacy.version import parse, LegacyVersion\n\n# Example of parsing a legacy version string\nlegacy_version_string = \"1.0.0.alpha0\"\nversion = parse(legacy_version_string)\n\nprint(f\"Parsed version: {version}\")\nprint(f\"Is it a LegacyVersion? {isinstance(version, LegacyVersion)}\")\n\n# Compare with a standard version\nstandard_version = parse(\"1.0.0a0\")\nprint(f\"Comparing {version} and {standard_version}: {version == standard_version}\")\n\n# The modern 'packaging' library would raise InvalidVersion for '1.0.0.alpha0'\n# To demonstrate, one would typically use a try-except block here\n# import packaging.version\n# try:\n#     packaging.version.parse(\"1.0.0.alpha0\")\n# except packaging.version.InvalidVersion as e:\n#     print(f\"Modern packaging error: {e}\")","lang":"python","description":"This quickstart demonstrates how to parse a 'legacy' version string using `packaging_legacy.version.parse`. It highlights that such a version will be represented by a `LegacyVersion` object, which is distinct from the standard `Version` object used for PEP 440 compliant versions. The example also implicitly contrasts this behavior with the modern `packaging` library, which would raise an `InvalidVersion` error for such a string."},"warnings":[{"fix":"If you rely on parsing non-PEP 440 compliant version strings (e.g., '1.0.0.alpha0') and expect a 'LegacyVersion' object, switch your imports from 'packaging' to 'packaging_legacy' for version parsing. Keep 'packaging' for modern version handling.","message":"The original 'packaging' library (pypa/packaging) removed support for 'LegacyVersion' and modified 'packaging.version.parse' to raise 'InvalidVersion' for non-PEP 440 compliant strings. This library, 'packaging-legacy', was created to provide a compatible API for those still needing to parse such versions.","severity":"breaking","affected_versions":"packaging>=22.0"},{"fix":"Always use `from packaging_legacy.version import parse` when you specifically need to handle legacy version formats. For all other standard version parsing, continue to use `from packaging.version import parse` from the main `packaging` library.","message":"Confusion between 'packaging' and 'packaging-legacy' is common. Using 'from packaging.version import parse' will *not* yield a 'LegacyVersion' object for non-standard versions; it will raise an error.","severity":"gotcha","affected_versions":"All versions of packaging>=22.0 and packaging-legacy"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If this is an intentional legacy version string, use `from packaging_legacy.version import parse` instead: `from packaging_legacy.version import parse; version = parse('1.0.0.alpha0')`.","cause":"You are attempting to parse a non-PEP 440 compliant version string using the modern `packaging` library (version 22.0 or higher), which no longer supports 'LegacyVersion' fallback.","error":"packaging.version.InvalidVersion: Invalid version: '1.0.0.alpha0'"},{"fix":"To access `LegacyVersion`, import it from `packaging_legacy`: `from packaging_legacy.version import LegacyVersion`.","cause":"The `LegacyVersion` class was removed from the `packaging` library in version 22.0. Your code is trying to import it from the main `packaging` package.","error":"ModuleNotFoundError: No module named 'packaging.version.LegacyVersion'"}]}