Parse, compare, bump, and validate semantic version strings
Project description
philiprehberger-semver
Parse, compare, bump, and validate semantic version strings.
Install
pip install philiprehberger-semver
Usage
from philiprehberger_semver import parse, bump, compare, satisfies, is_valid, sort_versions, next_pre
Parsing
v = parse("1.2.3-beta.1+build.42")
v.major # 1
v.minor # 2
v.patch # 3
v.pre # "beta.1"
v.build # "build.42"
str(v) # "1.2.3-beta.1+build.42"
A leading v prefix is accepted:
parse("v2.0.0") # Version(major=2, minor=0, patch=0)
Bumping
bump("1.2.3", "major") # "2.0.0"
bump("1.2.3", "minor") # "1.3.0"
bump("1.2.3", "patch") # "1.2.4"
Comparing
compare("1.2.3", "1.3.0") # -1
compare("2.0.0", "2.0.0") # 0
compare("3.0.0", "2.9.9") # 1
Range matching
satisfies("1.5.0", ">=1.0.0 <2.0.0") # True
satisfies("1.2.5", "^1.2.3") # True (>=1.2.3 <2.0.0)
satisfies("1.2.5", "~1.2.3") # True (>=1.2.3 <1.3.0)
satisfies("1.3.0", "~1.2.3") # False
Validation
is_valid("1.2.3") # True
is_valid("not-a-version") # False
Sorting
sort_versions(["2.0.0", "1.0.0", "1.1.0"]) # ["1.0.0", "1.1.0", "2.0.0"]
Pre-release generation
next_pre("1.2.3") # "1.2.4-rc.1"
next_pre("1.2.4-rc.1") # "1.2.4-rc.2"
next_pre("1.2.3", "beta") # "1.2.4-beta.1"
API
| Function | Description |
|---|---|
parse(version) |
Parse a semver string into a Version object |
bump(version, part) |
Bump major, minor, or patch and return the new version string |
compare(a, b) |
Compare two version strings, returns -1, 0, or 1 |
satisfies(version, range_str) |
Check if a version satisfies a range (>=, <, ^, ~) |
is_valid(version) |
Check if a string is valid semver |
sort_versions(versions) |
Sort a list of version strings in ascending order |
next_pre(version, prefix) |
Generate the next pre-release version string |
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_semver-0.1.2.tar.gz.
File metadata
- Download URL: philiprehberger_semver-0.1.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33d3cd4af67393d55ba9950db264626162b5a3aafcd62d26e042d927442f20ee
|
|
| MD5 |
594af61953098b54dd9e2e2aa5c9235d
|
|
| BLAKE2b-256 |
f9f030bcc30e8c134dfad34ab303b8303f5f4e600616e4f949d5290b74a24a43
|
File details
Details for the file philiprehberger_semver-0.1.2-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_semver-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0762fa0fb7524c457a833ed921b5835ee5ad622f2166e59d410bf027e00f66dd
|
|
| MD5 |
6b6697cc94c512efcfd8c6754c920cc2
|
|
| BLAKE2b-256 |
b1f2e49a8d4c0c2b2f78ae4fb7d94fd8f3a718d431aeb0ac6217b3a1590ddfb2
|