version

Version

class versions.version.Version(major, minor=0, patch=0, prerelease=None, build_metadata=None)[source]

A package version.

Parameters:
  • major (int) – Version major number
  • minor (int) – Version minor number
  • patch (int) – Version patch number
  • prerelease (str, int or None) – Version prerelease
  • build_metadata (None or str) – Version build metadata

This class constructor is usually not called directly. For version string parsing, see Version.parse.

classmethod parse(version_string)[source]

Parses a version_string and returns a Version object:

>>> Version.parse('1.0.0') > Version.parse('0.1')

True

Comparison

Version objects are comparable with standard operators:

>>> from versions import Version
>>> v1 = Version(1)
>>> v2 = Version(2)
>>> v1 == v2
False
>>> v1 != v2
True
>>> v1 > v2
False
>>> v1 < v2
True
>>> v1 >= v2
False
>>> v1 <= v2
True

Parsing

Version has a convenient parse static method to parse constrints strings into Version objects.

The parser does its best to normalize the passed in string into a Semantic Version 2.0 version:

>>> from versions import Version
>>> Version.parse('1')
Version.parse('1.0.0')
>>> Version.parse('1.0')
Version.parse('1.0.0')
>>> Version.parse('1.0.0')
Version.parse('1.0.0')
>>> Version.parse('1.0.0-dev')
Version.parse('1.0.0-dev')
>>> Version.parse('1.0.0+some.build.data')
Version.parse('1.0.0+build.data.some')
>>> Version.parse('1.0.0-alpha+some.build.data')
Version.parse('1.0.0-alpha+build.data.some')
>>> Version.parse('1.0.0-42')
Version.parse('1.0.0-42')

InvalidVersion

exception versions.version.InvalidVersion(version)[source]

Raised when failing to parse a version.

version = None

The bogus version.

Table Of Contents

Previous topic

API

Next topic

constraint