verlib2

0.3.2 · active · verified Thu Apr 16

verlib2 is a Python library that provides a standalone bundle of version parsing implementations, specifically `distutils.version` (PEP 386) and `packaging.version` (PEP 440). Its primary purpose is to offer these functionalities without requiring the `packaging` library as a dependency, and to provide a solution for projects that relied on `distutils.version` after `distutils` was removed from the Python standard library in Python 3.12. It is actively maintained with a steady release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use both the PEP 440-compliant `Version` class and the PEP 386-compliant `LooseVersion` and `StrictVersion` classes for version comparison and parsing. It highlights the differences in parsing rules between the two standards, particularly regarding development suffixes and strictness.

from verlib2 import Version
from verlib2.distutils.version import LooseVersion, StrictVersion

# Using PEP 440 (packaging.version) style
v1 = Version("1.0.dev456")
v2 = Version("1!1.2.rev33+123456")

assert v1 < v2
assert Version("1.0") == Version("1.0.0")

# Using PEP 386 (distutils.version) style
lv1 = LooseVersion("1.2.3b1")
lv2 = LooseVersion("1.2.3")

assert lv1 < lv2
assert LooseVersion("1.0") != LooseVersion("1.0.0") # Different behavior than PEP 440

try:
    sv = StrictVersion("1.2.3.4") # StrictVersion does not allow arbitrary suffixes
except ValueError as e:
    print(f"StrictVersion error: {e}")

view raw JSON →