Utilities

A set of small, helper utilities for dealing with Python packages.

Reference

packaging.utils.canonicalize_name(name)[source]

This function takes a valid Python package name, and returns the normalized form of it.

Parameters

name (str) – The name to normalize.

>>> from packaging.utils import canonicalize_name
>>> canonicalize_name("Django")
'django'
>>> canonicalize_name("oslo.concurrency")
'oslo-concurrency'
>>> canonicalize_name("requests")
'requests'
packaging.utils.canonicalize_version(version)[source]

This function takes a string representing a package version (or a Version instance), and returns the normalized form of it.

Parameters

version (str) – The version to normalize.

>>> from packaging.utils import canonicalize_version
>>> canonicalize_version('1.4.0.0.0')
'1.4'
packaging.utils.parse_wheel_filename(filename)[source]

This function takes the filename of a wheel file, and parses it, returning a tuple of name, version, build number and tags. The build number will be None if there is no build number in the wheel filename.

Parameters

filename (str) – The name of the wheel file.

>>> from packaging.utils import parse_wheel_filename
>>> from packaging.tags import Tag
>>> name, ver, build, tags = parse_wheel_filename("foo-1.0-py3-none-any.whl")
>>> name
'foo'
>>> ver
<Version('1.0')>
>>> tags == {Tag("py3", "none", "any")}
True
>>> build is None
True
packaging.utils.parse_sdist_filename(filename)[source]

This function takes the filename of a sdist file (as specified in the Source distribution format documentation), and parses it, returning a tuple of name and version.

Parameters

filename (str) – The name of the sdist file.

>>> from packaging.utils import parse_sdist_filename
>>> name, ver = parse_sdist_filename("foo-1.0.tar.gz")
>>> name
'foo'
>>> ver
<Version('1.0')>