parver: Parse and Manipulate Version Numbers
parver is a Python package designed for robust parsing and manipulation of PEP 440 compliant version numbers. It provides a `Version` class to represent versions and methods for common operations like bumping development or release segments, checking pre-release status, and normalization. The library is currently at version 0.5 and maintains a stable, active development status.
Warnings
- gotcha parver strictly adheres to PEP 440 for version parsing. Providing non-PEP 440 compliant strings may result in `InvalidVersion` exceptions or unexpected parsing behavior.
- gotcha When comparing `Version` objects, ensure both operands are `Version` instances for reliable and consistent results. While some direct comparisons with strings might work, it's generally safer to explicitly parse strings into `Version` objects before comparison.
- gotcha Users accustomed to Semantic Versioning (SemVer) might find `parver`'s `bump_*` methods behave differently. `parver` follows PEP 440's interpretation of version segments, which may not align directly with SemVer's `major.minor.patch` increment rules (e.g., `bump_release(index=2)` is used for patch).
Install
-
pip install parver
Imports
- Version
from parver import Version
Quickstart
from parver import Version
# Parse a version string
v = Version.parse('1.3.0.dev1')
print(f"Original version: {v}")
# Access parts of the version
print(f"Major: {v.major}, Minor: {v.minor}, Patch: {v.patch}")
print(f"Is pre-release: {v.is_prerelease}")
print(f"Development part: {v.dev}")
# Bump the development version
v_dev = v.bump_dev()
print(f"Bumped dev version: {v_dev}")
# Bump a release segment (e.g., patch, which is index 2)
v_patch = Version.parse('1.2.3').bump_release(index=2)
print(f"Bumped patch version: {v_patch}")
# Normalize a version
v_norm = Version.parse('v1.2.alpha-3').normalize()
print(f"Normalized version: {v_norm}")