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"]


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.

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.

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]]]