Skip to content
πŸ› οΈToolsShed

Semver Calculator

Compare semantic versions and check if a version satisfies a range (^, ~, >=, etc.).

Compare Two Versions

Range Examples

^1.2.3>= 1.2.3 < 2.0.0
~1.2.3>= 1.2.3 < 1.3.0
>=1.0.0 <2.0.0>= 1.0.0 AND < 2.0.0
1.0.0 - 2.0.0>= 1.0.0 <= 2.0.0
1.x.x || 2.x.x1.x OR 2.x

About this tool

Semantic Versioning (SemVer) is a standardized way to communicate software changes through version numbers like MAJOR.MINOR.PATCH. This tool helps you quickly compare versions and check whether a specific version satisfies a range constraint β€” essential when managing dependencies across projects, libraries, and frameworks.

To use it, enter a version number (e.g., 1.5.0) and a range expression (e.g., ^1.0.0 or >=1.0.0 <2.0.0) in the first section to see if the version matches. The second section lets you directly compare two versions to determine their ordering. Built-in examples show common range operators: caret (^) allows MINOR and PATCH updates, tilde (~) restricts to PATCH updates, and hyphen ranges (1.0.0 - 2.0.0) cover all versions between two bounds.

Developers and package managers rely on these version checks daily to ensure compatibility and prevent breaking changes. This calculator saves time during code review, dependency upgrades, and CI/CD pipelines where version constraints must be verified.

Frequently Asked Questions

Code Implementation

# pip install packaging
from packaging.version import Version
from packaging.specifiers import SpecifierSet

v1 = Version("1.2.3")
v2 = Version("2.0.0")
v3 = Version("1.2.3-alpha.1")  # Note: packaging uses PEP 440 syntax

# Comparison
print(v1 < v2)    # True
print(v1 == Version("1.2.3"))  # True

# Check if a version satisfies a specifier
spec = SpecifierSet(">=1.0.0,<2.0.0")
print(Version("1.5.0") in spec)   # True
print(Version("2.0.0") in spec)   # False
print(Version("0.9.0") in spec)   # False

# PEP 440 pre-release (different from semver!)
v_pre = Version("1.0.0a1")    # alpha 1
v_rc  = Version("1.0.0rc2")   # release candidate 2
print(v_pre < v_rc < Version("1.0.0"))  # True

# Sorting versions
versions = [Version(v) for v in ["2.0.0", "1.0.0", "1.5.0", "1.5.1"]]
print(sorted(versions))
# [<Version('1.0.0')>, <Version('1.5.0')>, <Version('1.5.1')>, <Version('2.0.0')>]

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.