easysemver
This package provides utilities for comparing SemVer versions,
with special attention on the correct treatment of prerelease parts.
Installation
easysemver
can be installed from PyPI:
pip install easysemver
Usage
Before versions can be compared, they must be converted into Version
objects. If the version
is not valid SemVer, a TypeError
will be raised.
from easysemver import Version
version = Version("20230809-1")
version = Version("1.2.3")
version = Version("1.2.3-alpha.0+abcdefg")
Version("1.2.3") < Version("1.2.4")
Version("1.2.3") < Version("2.0.0")
Version("1.2.3") < Version("1.2.4-alpha.0")
Version("1.2.3-alpha.0") < Version("1.2.3")
Version("1.2.3-alpha.0") < Version("1.2.3-alpha.100")
Version("1.2.3-alpha.0") < Version("1.2.3-beta.0")
Version("1.2.3") == Version("1.2.3+abcdefg")
Versions can also be compared to a SemVer range, which consists of a number of constraints
separated by commas. Similar to Version
, a TypeError
will be raised if the constraints
are not valid.
The supported constraints are SemVer versions with an operator, where the supported operators
are ==
, !=
, >=
, >
, <=
and <
.
from easysemver import Range, Version
Version("1.2.3") in Range(">=1.0.0,<2.0.0")
Version("1.2.3") in Range(">=2.0.0")
Version("1.2.3-alpha.0") in Range(">=1.0.0")
Version("1.2.3-alpha.0") in Range(">=1.0.0-0")
Version("1.2.3") in Range(">=1.0.0,<2.0.0,!=1.2.3")
Version("1.2.4") in Range(">=1.0.0,<2.0.0,!=1.2.3")