Skip to main content

Package version handling library

Project description

https://badge.fury.io/py/versions.png https://secure.travis-ci.org/pmuller/versions.png?branch=master

Documentation: versions.rtfd.org

Basic usage

Version comparisons example:

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

Version.parse expects a Semantic Version 2.0 string and returns a corresponding Version object:

>>> from versions import Version
>>> v = Version.parse('1.2.0-dev+foo.bar')
>>> v.major, v.minor, v.patch, v.prerelease, v.build_metadata
(1, 2, 0, 'dev', 'foo.bar')

If it isn’t a semantic version string, the parser tries to normalize it:

>>> v = Version.parse('1')
>>> v.major, v.minor, v.patch, v.prerelease, v.build_metadata
(1, 0, 0, None, None)

Version constraint matching

versions also implements version constraint parsing and evaluation:

>>> from versions import Constraint
>>> Constraint.parse('>1').match('2')
True
>>> Constraint.parse('<2').match(Version.parse('1'))
True

For conveniance, constraint matching can be tested using the in operator:

>>> '1.5' in Constraint.parse('<2')
True
>>> Version(2) in Constraint.parse('!=2')
False

Constraints can be merged using Constraints:

>>> from versions import Constraints
>>> '1.0' in Constraints.parse('>1,<2')
False
>>> '1.5' in Constraints.parse('>1,<2')
True
>>> '2.0' in Constraints.parse('>1,<2')
False
Bitdeli badge

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

versions-0.10.0.tar.gz (13.9 kB view details)

Uploaded Source

File details

Details for the file versions-0.10.0.tar.gz.

File metadata

  • Download URL: versions-0.10.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for versions-0.10.0.tar.gz
Algorithm Hash digest
SHA256 cbeb39bc303a975e6b22e1bc36d93427ced2c745bf633b7ebb99769348f1a17f
MD5 b4ac67411cfa700f5499db922ece2929
BLAKE2b-256 c4e516cda13ca5d34a68d8216bfcc263affaa05ac54afb07fc8c10524d2a0ad5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page