Tags

Wheels encode the Python interpreter, ABI, and platform that they support in their filenames using platform compatibility tags. This module provides support for both parsing these tags as well as discovering what tags the running Python interpreter supports.

Usage

>>> from packaging.tags import Tag, sys_tags
>>> import sys
>>> looking_for = Tag("py{major}".format(major=sys.version_info.major), "none", "any")
>>> supported_tags = list(sys_tags())
>>> looking_for in supported_tags
True
>>> really_old = Tag("py1", "none", "any")
>>> wheels = {really_old, looking_for}
>>> best_wheel = None
>>> for supported_tag in supported_tags:
...     for wheel_tag in wheels:
...         if supported_tag == wheel_tag:
...             best_wheel = wheel_tag
...             break
>>> best_wheel == looking_for
True

Reference

High Level Interface

The following functions are the main interface to the library, and are typically the only items that applications should need to reference, in order to parse and check tags.

class packaging.tags.Tag

A representation of the tag triple for a wheel.

Instances are considered immutable and thus are hashable. Equality checking is also supported.

__init__(interpreter, abi, platform)
Parameters:
  • interpreter (str)

  • abi (str)

  • platform (str)

Return type:

None

packaging.tags.parse_tag(tag)

Parses the provided tag (e.g. py3-none-any) into a frozenset of Tag instances.

Returning a set is required due to the possibility that the tag is a compressed tag set.

Parameters:

tag (str)

Return type:

frozenset[Tag]

packaging.tags.sys_tags(*, warn=False)

Returns the sequence of tag triples for the running interpreter.

The order of the sequence corresponds to priority order for the interpreter, from most to least important.

Parameters:

warn (bool)

Return type:

Iterator[Tag]

Low Level Interface

The following functions are low-level implementation details. They should typically not be needed in application code, unless the application has specialised requirements (for example, constructing sets of supported tags for environments other than the running interpreter).

These functions capture the precise details of which environments support which tags. That information is not defined in the compatibility tag standards but is noted as being up to the implementation to provide.

packaging.tags.INTERPRETER_SHORT_NAMES

A dictionary mapping interpreter names to their abbreviation codes (e.g. "cpython" is "cp"). All interpreter names are lower-case.

packaging.tags.interpreter_name()

Returns the name of the running interpreter.

Some implementations have a reserved, two-letter abbreviation which will be returned when appropriate.

Return type:

str

packaging.tags.interpreter_version(*, warn=False)

Returns the version of the running interpreter.

Parameters:

warn (bool)

Return type:

str

packaging.tags.mac_platforms(version=None, arch=None)

Yields the platform tags for a macOS system.

The version parameter is a two-item tuple specifying the macOS version to generate platform tags for. The arch parameter is the CPU architecture to generate platform tags for. Both parameters default to the appropriate value for the current system.

Parameters:
  • version (Tuple[int, int] | None)

  • arch (str | None)

Return type:

Iterator[str]

packaging.tags.ios_platforms(version=None, multiarch=None)

Yields the platform tags for an iOS system.

Parameters:
  • version (Tuple[int, int] | None) – A two-item tuple specifying the iOS version to generate platform tags for. Defaults to the current iOS version.

  • multiarch (str | None) – The CPU architecture+ABI to generate platform tags for - (the value used by sys.implementation._multiarch e.g., arm64_iphoneos or x84_64_iphonesimulator). Defaults to the current multiarch value.

Return type:

Iterator[str]

packaging.tags.android_platforms(api_level=None, abi=None)

Yields the platform tags for Android. If this function is invoked on non-Android platforms, the api_level and abi arguments are required.

Parameters:
  • api_level (int) – The maximum API level to return. Defaults to the current system’s version, as returned by platform.android_ver.

  • abi (str) – The Android ABI, e.g. arm64_v8a. Defaults to the current system’s ABI , as returned by sysconfig.get_platform. Hyphens and periods will be replaced with underscores.

Return type:

Iterator[str]

packaging.tags.platform_tags()

Provides the platform tags for this installation.

Return type:

Iterator[str]

packaging.tags.compatible_tags(python_version=None, interpreter=None, platforms=None)

Yields the sequence of tags that are compatible with a specific version of Python.

The tags consist of: - py*-none-<platform> - <interpreter>-none-any # … if interpreter is provided. - py*-none-any

Parameters:
  • python_version (Sequence[int] | None)

  • interpreter (str | None)

  • platforms (Iterable[str] | None)

Return type:

Iterator[Tag]

packaging.tags.cpython_tags(python_version=None, abis=None, platforms=None, *, warn=False)

Yields the tags for a CPython interpreter.

The tags consist of: - cp<python_version>-<abi>-<platform> - cp<python_version>-abi3-<platform> - cp<python_version>-none-<platform> - cp<less than python_version>-abi3-<platform> # Older Python versions down to 3.2.

If python_version only specifies a major version then user-provided ABIs and the ‘none’ ABItag will be used.

If ‘abi3’ or ‘none’ are specified in ‘abis’ then they will be yielded at their normal position and not at the beginning.

Parameters:
  • python_version (Sequence[int] | None)

  • abis (Iterable[str] | None)

  • platforms (Iterable[str] | None)

  • warn (bool)

Return type:

Iterator[Tag]

packaging.tags.generic_tags(interpreter=None, abis=None, platforms=None, *, warn=False)

Yields the tags for a generic interpreter.

The tags consist of: - <interpreter>-<abi>-<platform>

The “none” ABI will be added if it was not explicitly provided.

Parameters:
  • interpreter (str | None)

  • abis (Iterable[str] | None)

  • platforms (Iterable[str] | None)

  • warn (bool)

Return type:

Iterator[Tag]