Skip to main content

versions

License Version Downloads Discord

Documentation Check Test Coverage

Parsing, inspecting and specifying versions.

Installing

Python 3.8 or above is required.

pip

Installing the library with pip is quite simple:

$ pip install versions

Alternatively, the library can be installed from source:

$ git clone https://github.com/nekitdev/versions.git
$ cd versions
$ python -m pip install .

poetry

You can add versions as a dependency with the following command:

$ poetry add versions

Or by directly specifying it in the configuration like so:

[tool.poetry.dependencies]
versions = "^2.1.2"

Alternatively, you can add it directly from the source:

[tool.poetry.dependencies.versions]
git = "https://github.com/nekitdev/versions.git"

Examples

Versions

parse_version is used to parse versions:

from versions import parse_version

version = parse_version("1.0.0-dev.1+build.1")

print(version)  # 1.0.0-dev.1+build.1

Segments

All version segments can be fetched with their respective names:

>>> print(version.release)
1.0.0
>>> version.release.parts
(1, 0, 0)
>>> print(version.dev)
dev.1
>>> (version.dev.phase, version.dev.value)
("dev", 1)
>>> print(version.local)
build.1
>>> version.local.parts
("build", 1)

Comparison

Versions support total ordering:

>>> v1 = parse_version("1.0.0")
>>> v2 = parse_version("2.0.0")
>>> v1 == v2
False
>>> v1 != v2
True
>>> v1 >= v2
False
>>> v1 <= v2
True
>>> v1 > v2
False
>>> v1 < v2
True

Specification

versions also supports specifying version requirements and matching version against them.

Since versions support total ordering, they can be checked using version sets (via parse_version_set):

>>> from versions import parse_version, parse_version_set
>>> version_set = parse_version_set("^1.0.0")
>>> version_set
<VersionRange (>= 1.0.0, < 2.0.0)>
>>> version = parse_version("1.3.0")
>>> version.matches(version_set)
True
>>> another = parse_version("2.2.0")
>>> another.matches(version_set)
False

Alternatively, one can use specifiers, which are similar to version sets, except they retain the structure of specifications given (via parse_specifier):

>>> from versions import parse_specifier, parse_version
>>> specifier = parse_specifier("^1.0.0")
>>> specifier
<SpecifierOne (^1.0.0)>
>>> version = parse_version("1.3.0")
>>> version.matches(specifier)
True
>>> another = parse_version("2.2.0")
>>> another.matches(specifier)
False

Versioned

versions allows users to access versions of items that have the __version__ attribute:

>>> from versions import get_version
>>> import versions
>>> get_version(versions)
<Version (2.1.2)>

Documentation

You can find the documentation here.

Support

If you need support with the library, you can send an email or refer to the official Discord server.

Changelog

You can find the changelog here.

Security Policy

You can find the Security Policy of versions here.

Contributing

If you are interested in contributing to versions, make sure to take a look at the Contributing Guide, as well as the Code of Conduct.

License

versions is licensed under the MIT License terms. See License for details.

Release files for versions 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for versions 2.1.2
File Size Uploaded
versions-2.1.2.tar.gz 35.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for versions 2.1.2
File Interpreter ABI Platform
versions-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 78.7 kB

Release files / versions-2.1.2.tar.gz

Download URL versions-2.1.2.tar.gz
Size 35.8 kB
Tags Source
SHA-256 checksum
How to use checksums
78ff96645a3b1afea09ca2c8482bcca0cd68d816a6a729565502c2eb6f2ef466
BLAKE2b-256 checksum
How to use checksums
2862bf254f5c7d7aa884036ea9cdae13d32803849175d3e4a56c381b88878c33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.10.12 Linux/6.2.0-1019-azure

Release files / versions-2.1.2-py3-none-any.whl

Download URL versions-2.1.2-py3-none-any.whl
Size 42.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca0d4968ecb382b351e73128276f166aefef8fba67f37c3d19c03d356c95dfeb
BLAKE2b-256 checksum
How to use checksums
ffe4509d13728f45cc64de68df809419dfdf4bacd60d2545066a7211acd515f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.10.12 Linux/6.2.0-1019-azure

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.6.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page