Home

Awesome

Python bindings for libversion

<a href="https://repology.org/metapackage/python:libversion/versions"> <img src="https://repology.org/badge/vertical-allrepos/python:libversion.svg" alt="py-libversion packaging status" align="right"> </a>

CI PyPI downloads PyPI version PyPI pythons Github commits (since latest release)

Purpose

Python bindings for libversion, which provides fast, powerful and correct generic version string comparison algorithm.

See libversion repository for more details on the algorithm.

Performance

libversion is 10x to 100x faster than other version comparison facilities widely used in Python world.

Facilitycomps/sec
libversion.version_compare23492.81K
libversion.version_compare3219.02K
libversion.Version374.08K
tuple(map(int, (v.split('.'))))206.02K
cmp_version.cmp_version189.15K
cmp_version.VersionString156.42K
distutils.version.StrictVersion75.00K
version.Version71.39K
distutils.version.LooseVersion51.38K
pkg_resources.parse_version22.26K

Correctness

libversion handles certain complex version cases better than other version comparison facilities. Here are some example cases where others fail:

Test caselibversiontupleStrictVersionLooseVersionparse_versioncmp_version
1.0 == 1.0.0okincorrect (<)okincorrect (<)okok
1.2_3 == 1.2-3okfailfailincorrect (>)incorrect (<)ok
1.2.3 == 1.2-3okfailfailfailincorrect (>)incorrect (<)
1.0alpha1 == 1.0.alpha1okfailfailokokincorrect (>)
1.0rc1 < 1.0okfailfailincorrect (>)okincorrect (>)
1.0 < 1.0patch1okfailfailokincorrect (>)ok
1.0.2a < 1.0.2gokfailfailokincorrect (>)ok

Note 1: fail means that attempt to compare versions has thrown an exception, usually bacause a library cannot parse specific version string.

Note 2: version module was not able to complete any tests as it's a strict semantic version implementation which require 3 version components. Also, it does not support Python 3 without modification.

Python wrapper features

Requirements

Example code

from libversion import Version, version_compare

assert(version_compare("0.9", "1.1") < 0)
assert(version_compare("1.0", "1.0.0") == 0)
assert(version_compare("1.1", "0.9") > 0)

assert(Version("0.9") < Version("1.1"))
assert(Version("1.0") ==  Version("1.0.0"))
assert(Version("1.1") > Version("0.9"))

assert(Version("0.999") < Version("1.0alpha1"))
assert(Version("1.0alpha1") < Version("1.0alpha2"))
assert(Version("1.0alpha2") < Version("1.0beta1"))
assert(Version("1.0beta1") < Version("1.0pre1"))
assert(Version("1.0pre1") < Version("1.0rc1"))
assert(Version("1.0rc1") < Version("1.0"))
assert(Version("1.0") < Version("1.0patch1"))

License

MIT license, copyright (c) 2017-2018 Dmitry Marakasov amdmi3@amdmi3.ru.