{"id":8086,"library":"dist-meta","title":"Parse and Create Python Distribution Metadata","description":"dist-meta is a Python library (current version 0.9.0) designed to parse and create Python distribution metadata, primarily interacting with `dist-info/METADATA` files. It provides tools for reading distribution information, entry points, and `RECORD` files. Releases are made irregularly as features are added or issues resolved.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/repo-helper/dist-meta","tags":["packaging","metadata","pypi","distribution","wheels"],"install":[{"cmd":"pip install dist-meta","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Utility library required for core functionality.","package":"domdf-python-tools","optional":false},{"reason":"Archival utilities for distribution processing.","package":"handy-archives","optional":false}],"imports":[{"symbol":"loads","correct":"from dist_meta.metadata import loads"},{"symbol":"get_distribution","correct":"from dist_meta.distributions import get_distribution"},{"symbol":"EntryPoint","correct":"from dist_meta.entry_points import EntryPoint"}],"quickstart":{"code":"from dist_meta.metadata import loads\n\nmetadata_content = '''\\\nMetadata-Version: 2.1\nName: my-example-package\nVersion: 1.2.3\nSummary: A simple example Python package.\nAuthor: Example Developer\nAuthor-Email: dev@example.com\nRequires-Python: >=3.6.1\n''')\n\nparsed_metadata = loads(metadata_content)\n\nprint(f\"Package Name: {parsed_metadata['Name']}\")\nprint(f\"Package Version: {parsed_metadata['Version']}\")\nprint(f\"Requires Python: {parsed_metadata['Requires-Python']}\")","lang":"python","description":"This quickstart demonstrates how to parse a Python distribution's metadata string using `dist_meta.metadata.loads`. This is useful for programmatically inspecting package information."},"warnings":[{"fix":"Refer to the official Python packaging specifications for the metadata version you are working with. Validate metadata structure and required fields before parsing.","message":"When parsing metadata, ensure the input string or file adheres to the Python Core Metadata Specifications (e.g., PEP 643 for Metadata-Version 2.2+ or earlier PEPs). Incorrectly formatted or incomplete metadata may lead to parsing errors or missing fields.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For string content, use `dist_meta.metadata.loads()`. For file paths or file objects, open the file and pass the content to `loads()` or the file object to `load()` respectively.","message":"The `loads()` function is for parsing a string, while `load()` is for parsing a file-like object. Using a file path directly with `loads()` or string content with `load()` will result in `TypeError` or `AttributeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure all mandatory fields (e.g., `Metadata-Version`, `Name`, `Version`) are present and correctly formatted in the metadata string or file being parsed.","cause":"The input metadata string or file is missing a required field, such as 'Name' or 'Version', which are mandatory in Python distribution metadata.","error":"dist_meta.metadata.MissingFieldError: 'Name'"},{"fix":"Use `from dist_meta.metadata import loads` and pass the metadata as a string to the `loads()` function. Alternatively, if you intend to read from a file, open the file and pass the file object to `load()`.","cause":"Attempted to pass a string containing metadata directly to `dist_meta.metadata.load()`, which expects a file-like object with a `read()` method.","error":"AttributeError: 'str' object has no attribute 'read'"}]}