Skip to main content

Simple semantic versioning module

Project description

Python 3.7+ Latest version released on PyPI Tests coverage Package license

amtSemVer is a Python 3 package that provides a very simplistic support for the Semantic Versioning 2.0.

Basic Usage

Install with pip:

pip install amtsemver

Import the SemanticVersion class in your python code

from amtSemVer import SemanticVersion

You can create a new version from its constituents:

# create a version with all the parameters 1.2.3-alpha+2345
version_a = SemanticVersion(major=1, minor=2, patch=3, pre_release="alpha", build="2345")

# create a simple version 2.0.0
version_b = SemanticVersion(major=2, minor=0, patch=0)

Or by parsing a string:

# create an object from the string
version_a = SemanticVersion.parse("1.2.3-alpha+2345")

# this works too
version_b = SemanticVersion.parse("1.2.3")
# or (1.2.0)
version_c = SemanticVersion.parse("1.2")
# or (1.0.0)
version_d = SemanticVersion.parse("1")
# or even (1.0.0-alpha)
version_e = SemanticVersion.parse("1+alpha")

__str__ representation of an object returns the following format major.minor.patch[-pre_release][+build]

>>> a = SemanticVersion.parse("1.2.3-alpha+2345")
>>> str(a)

__repr__ returns a string that can be evaluated back as an object.

>>> a = SemanticVersion.parse("1.2.3-alpha+2345")
>>> b = repr(a)
>>> b
'SemanticVersion(major=1, minor=2, patch=3, pre_release="alpha", build="2345")'
>>> c = eval(b)
>>> c == a

Object supports the rich comparison operators:

  • Equal: a == b
  • Not Equal: a != b
  • Lesser: a < b
  • Lesser or Equal: a <= b
  • Greater: a > b
  • Greater or Equal: a >= b
>>> a = SemanticVersion.parse("1.2.0")
>>> b = SemanticVersion.parse("1.2.0-alpha")
>>> a > b
>>> a != b
>>> a <= b


Run tests:

$ tox


This package is released under the Apache License 2.0. See the bundled LICENSE file for details.

Project details

Release history Release notifications

Download files

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

Files for amtSemVer, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size amtSemVer-1.0.0-py3-none-any.whl (8.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size amtSemVer-1.0.0.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page