Skip to main content

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

# Not a valid SemVer version, so raises TypeError
version = Version("20230809-1")
# Create a SemVer version
version = Version("1.2.3")
# Prerelease and build parts are supported
version = Version("1.2.3-alpha.0+abcdefg")

# Comparing versions respects prerelease parts
#   The following all resolve to True
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")
#   Prerelease parts that are all digits are compared as numbers
Version("1.2.3-alpha.0") < Version("1.2.3-alpha.100")
#   Prerelease parts that are strings are compared as strings
Version("1.2.3-alpha.0") < Version("1.2.3-beta.0")
#   Note that build parts don't affect comparison
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

# Resolves to True
Version("1.2.3") in Range(">=1.0.0,<2.0.0")
# Resolves to False
Version("1.2.3") in Range(">=2.0.0")
# Prerelease versions are only considered part of a range if the lower bound includes a prerelease part
#   Resolves to False
Version("1.2.3-alpha.0") in Range(">=1.0.0")
#   Resolves to True
Version("1.2.3-alpha.0") in Range(">=1.0.0-0")
# Specific versions can be exclulded
#   Resolves to False
Version("1.2.3") in Range(">=1.0.0,<2.0.0,!=1.2.3")
#   Resolves to True
Version("1.2.4") in Range(">=1.0.0,<2.0.0,!=1.2.3")

Metadata

Release files for easysemver 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easysemver 0.2.0
File Size Uploaded
easysemver-0.2.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easysemver 0.2.0
File Interpreter ABI Platform
easysemver-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / easysemver-0.2.0.tar.gz

Download URL easysemver-0.2.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a62985b65993beec3b8b41154a31c34a49f360c2464dceaff1ac9b007242a7cd
BLAKE2b-256 checksum
How to use checksums
938dd2a02fb567fb1e0ff47531f726be1e8a72d4e386f9ee04c7e5ac417c5b30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / easysemver-0.2.0-py3-none-any.whl

Download URL easysemver-0.2.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fd25a79dff01085ea11a5364395a080c5e2d94b2369e6312da0f738c6030307
BLAKE2b-256 checksum
How to use checksums
4c906834f671582847987a74ab0cd2a35f3cdfbba6e24d7e803fca4dbd9b8f83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page