Semantic Versioning Library

2.10.0 · active · verified Sun Mar 29

This Python library provides tools to handle Semantic Versioning (SemVer) strictly following the 2.0.0 scheme. It offers classes for parsing, comparing, and manipulating version numbers and defining requirement specifications. As of version 2.10.0, it is actively maintained with a stable release cadence.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create Version objects, access their components, perform comparisons, and use SimpleSpec to check if a version falls within a specified range.

from semantic_version import Version, SimpleSpec

# Create a Version object
v = Version('1.2.3-alpha+build.123')
print(f"Version: {v}")
print(f"Major: {v.major}, Minor: {v.minor}, Patch: {v.patch}")
print(f"Prerelease: {v.prerelease}, Build: {v.build}")

# Compare versions
v1 = Version('1.0.0')
v2 = Version('1.0.1')
print(f"Is {v1} < {v2}? {v1 < v2}")

# Define and use a SimpleSpec
spec = SimpleSpec('>=1.0.0,<2.0.0')
print(f"Does {v1} match spec '>1.0.0,<2.0.0'? {v1 in spec}")
print(f"Does {v2} match spec '>1.0.0,<2.0.0'? {v2 in spec}")
print(f"Does Version('2.0.0') match spec '>1.0.0,<2.0.0'? {Version('2.0.0') in spec}")

view raw JSON →