Both source distributions and binary distributions (_sdists_ and _wheels_, respectively) contain files recording the core metadata for the distribution. This information is used for everything from recording the name of the distribution to the installation dependencies.


>>> from packaging.metadata import parse_email
>>> metadata = "Metadata-Version: 2.3\nName: packaging\nVersion: 24.0"
>>> raw, unparsed = parse_email(metadata)
>>> raw["metadata_version"]
>>> raw["name"]
>>> raw["version"]
>>> from packaging.metadata import Metadata
>>> parsed = Metadata.from_raw(raw)
>>> parsed.version


High Level Interface#

class packaging.metadata.Metadata#

Representation of distribution metadata.

Compared to RawMetadata, this class provides objects representing metadata fields instead of only using built-in types. Any invalid metadata will cause InvalidMetadata to be raised (with a __cause__ attribute as appropriate).

classmethod from_raw(data, *, validate=True)#

Create an instance from RawMetadata.

If validate is true, all metadata will be validated. All exceptions related to validation will be gathered and raised as an ExceptionGroup.

Return type:


classmethod from_email(data, *, validate=True)#

Parse metadata from email headers.

If validate is true, the metadata will be validated. All exceptions related to validation will be gathered and raised as an ExceptionGroup.

Return type:


metadata_version: _Validator[Literal['1.0', '1.1', '1.2', '2.1', '2.2', '2.3']]#

Metadata-Version (required; validated to be a valid metadata version)

name: _Validator[str]#

Name (required; validated using canonicalize_name() and its validate parameter)

version: _Validator[Version]#

Version (required)

dynamic: _Validator[List[str] | None]#

Dynamic (multiple use) (validated against core metadata field names and lowercased)

platforms: _Validator[List[str] | None]#

Platform (multiple use)

supported_platforms: _Validator[List[str] | None]#

Supported-Platform (multiple use)

summary: _Validator[str | None]#

Summary (validated to contain no newlines)

description: _Validator[str | None]#


description_content_type: _Validator[str | None]#

Description-Content-Type (validated)

keywords: _Validator[List[str] | None]#


home_page: _Validator[str | None]#


download_url: _Validator[str | None]#


author: _Validator[str | None]#


author_email: _Validator[str | None]#


maintainer: _Validator[str | None]#


maintainer_email: _Validator[str | None]#


license: _Validator[str | None]#


classifiers: _Validator[List[str] | None]#

Classifier (multiple use)

requires_dist: _Validator[List[Requirement] | None]#

Requires-Dist (multiple use)

requires_python: _Validator[SpecifierSet | None]#


requires_external: _Validator[List[str] | None]#

Requires-External (multiple use)

project_urls: _Validator[Dict[str, str] | None]#

Project-URL (multiple-use)

provides_extra: _Validator[List[NormalizedName] | None]#

Provides-Extra (multiple use)

provides_dist: _Validator[List[str] | None]#

Provides-Dist (multiple use)

obsoletes_dist: _Validator[List[str] | None]#

Obsoletes-Dist (multiple use)

requires: _Validator[List[str] | None]#

Requires (deprecated)

provides: _Validator[List[str] | None]#

Provides (deprecated)

obsoletes: _Validator[List[str] | None]#

Obsoletes (deprecated)

Low Level Interface#

class packaging.metadata.RawMetadata#

A dictionary of raw core metadata.

Each field in core metadata maps to a key of this dictionary (when data is provided). The key is lower-case and underscores are used instead of dashes compared to the equivalent core metadata field. Any core metadata field that can be specified multiple times or can hold multiple values in a single field have a key with a plural name. See Metadata whose attributes match the keys of this dictionary.

Core metadata fields that can be specified multiple times are stored as a list or dict depending on which is appropriate for the field. Any fields which hold multiple values in a single field are stored as a list.

static __new__(cls, /, *args, **kwargs)#

Parse a distribution’s metadata stored as email headers (e.g. from METADATA).

This function returns a two-item tuple of dicts. The first dict is of recognized fields from the core metadata specification. Fields that can be parsed and translated into Python’s built-in types are converted appropriately. All other fields are left as-is. Fields that are allowed to appear multiple times are stored as lists.

The second dict contains all other fields from the metadata. This includes any unrecognized fields. It also includes any fields which are expected to be parsed into a built-in type but were not formatted appropriately. Finally, any fields that are expected to appear only once but are repeated are included in this dict.


data (bytes | str) –

Return type:

Tuple[RawMetadata, Dict[str, List[str]]]


class packaging.metadata.InvalidMetadata#

A metadata field contains invalid data.

__init__(field, message)#
  • field (str) –

  • message (str) –

Return type:


field: str#

The name of the field that contains invalid data.

class packaging.metadata.ExceptionGroup#

A minimal implementation of ExceptionGroup from Python 3.11.

If ExceptionGroup is already defined by Python itself, that version is used instead.

__init__(message, exceptions)#
Return type: