Skip to main content

larzsemver

Semantic Versioning 2.0.0. Pure Python, zero dependencies.

Parse 1.2.3-rc.1+build, compare versions by the exact SemVer precedence rules (including the fiddly pre-release ordering), sort them, bump them, and test whether a version satisfies a range like ^1.2.0 or >=1.2.0 <2.0.0.

from larzsemver import Version, satisfies, max_satisfying

Version.parse("1.2.3") < Version.parse("1.10.0")     # True (numeric, not string!)
satisfies("1.5.2", "^1.2.0")                          # True
satisfies("2.0.0", "^1.2.0")                          # False
max_satisfying(["1.0.0", "1.5.0", "2.0.0"], "^1.0.0") # Version('1.5.0')

Why

  • Spec-correct precedence. 1.10.0 > 1.2.3 (numeric, not lexicographic), and the full pre-release ordering (1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0) - tested against the example in the spec.
  • Range matching. ^ (caret), ~ (tilde), x-ranges (1.2.x), comparators (>=1.0.0 <2.0.0), *, AND (space), and OR (||) - and max_satisfying.
  • Zero dependencies. No semver, no packaging.

Install

pip install larzsemver

Usage

from larzsemver import Version, satisfies, sort_versions, max_satisfying

v = Version.parse("2.1.0-rc.1+build.7")
v.major, v.minor, v.patch, v.prerelease, v.build
v.bump_minor()                          # Version('2.2.0')
sorted([Version.parse("1.0.0"), Version.parse("0.9.0")])

satisfies("1.4.0", "~1.4.0")            # >=1.4.0 <1.5.0
satisfies("1.4.0", ">=1.0.0 <2.0.0 || 3.x")
max_satisfying(available_versions, "^2.0.0")

Tests

python -m unittest discover -s tests -v   # 18 tests incl. the spec precedence chain

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT (c) larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzsemver-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzsemver-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file larzsemver-0.1.0.tar.gz.

File metadata

  • Download URL: larzsemver-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzsemver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bfbf7f782c222037f854cc96a6e9785e8f3d73a8ae5d6e2a33acca0232f2371a
MD5 7749050ebc972050ec996d71d0fa9257
BLAKE2b-256 45bdc74a5c2cd1247d473702f91efbe3cd14e316205ac65e3deeb330e8226aca

See more details on using hashes here.

File details

Details for the file larzsemver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzsemver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzsemver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1febf8fdb19b1f7e2b179fff6384bca3ba3a3b7e48c6619f3351140c01b84e95
MD5 94f41206d2aa45e6539d52569a2ae31d
BLAKE2b-256 de2f1f518e086a8b8cc1e6d3495154e7a75b8732820de61e5e64cc97260b466f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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