{"id":8314,"library":"metadata-please","title":"Metadata Please","description":"metadata-please is a Python library designed for simple extraction of metadata from Python distribution artifacts. It supports extracting metadata from source distributions (sdists), wheel files, and project directories containing `pyproject.toml` or `setup.py`. The current version is 0.2.1, with releases occurring on an as-needed basis for improvements and bug fixes.","status":"active","version":"0.2.1","language":"en","source_language":"en","source_url":"https://github.com/python-packaging/metadata-please/","tags":["packaging","metadata","sdist","wheel","pyproject.toml","setup.py","build system"],"install":[{"cmd":"pip install metadata-please","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"get_metadata","correct":"from metadata_please import get_metadata"}],"quickstart":{"code":"from metadata_please import get_metadata\nfrom pathlib import Path\nimport tempfile\nimport shutil\n\n# Create dummy files for demonstration\ndef create_dummy_sdist(path):\n    path.mkdir(parents=True, exist_ok=True)\n    with open(path / 'setup.py', 'w') as f:\n        f.write(\"from setuptools import setup; setup(name='dummy_sdist', version='0.1.0')\")\n    # In a real scenario, you'd run `python setup.py sdist`\n    # For this example, we'll just point to the dir as if it were an sdist source\n\ndef create_dummy_pyproject_toml(path):\n    path.mkdir(parents=True, exist_ok=True)\n    with open(path / 'pyproject.toml', 'w') as f:\n        f.write('[project]\\nname = \"dummy-toml\"\\nversion = \"0.2.0\"')\n\nwith tempfile.TemporaryDirectory() as tmpdir:\n    tmp_path = Path(tmpdir)\n\n    # Example 1: Project directory with setup.py (simplified as source dir)\n    sdist_source_dir = tmp_path / \"dummy_sdist_project\"\n    create_dummy_sdist(sdist_source_dir)\n    metadata_sdist = get_metadata(sdist_source_dir)\n    print(f\"sdist project Name: {metadata_sdist.name}, Version: {metadata_sdist.version}\")\n\n    # Example 2: Project directory with pyproject.toml\n    pyproject_source_dir = tmp_path / \"dummy_toml_project\"\n    create_dummy_pyproject_toml(pyproject_source_dir)\n    metadata_toml = get_metadata(pyproject_source_dir)\n    print(f\"pyproject.toml project Name: {metadata_toml.name}, Version: {metadata_toml.version}\")\n\n    # Note: For actual .tar.gz (sdist) or .whl (wheel) files,\n    # you would replace the paths with your actual artifact files.\n    # Creating real sdist/wheel files dynamically for a quickstart is complex.\n    # The library is designed to work with these file types directly.\n    # Example (conceptual for artifact files):\n    # real_sdist_path = Path(\"path/to/your_package-1.0.0.tar.gz\")\n    # metadata_real_sdist = get_metadata(real_sdist_path)\n    # print(f\"Real sdist Name: {metadata_real_sdist.name}\")\n","lang":"python","description":"The `get_metadata` function is the primary entry point for `metadata-please`. It takes a `Path` object pointing to a Python artifact (sdist, wheel) or a project source directory (containing `pyproject.toml` or `setup.py`) and returns a metadata object. The example demonstrates usage for project source directories."},"warnings":[{"fix":"For comprehensive runtime introspection of *installed* packages, consider `importlib.metadata` (standard library for Python 3.8+ or `importlib_metadata` backport).","message":"The library primarily extracts *core metadata* as defined by Python packaging standards. While it can read `setup.py` and `pyproject.toml`, it may not extract all arbitrary fields or dynamic metadata generated by complex build systems (e.g., `setuptools_scm`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `setup.py` files conform to standard, readable patterns for metadata declaration. For projects using `pyproject.toml` (PEP 621), metadata extraction is generally more reliable.","message":"Direct parsing of `setup.py` (added in v0.2.0) has inherent limitations as `setup.py` is executable Python code. `metadata-please` attempts to safely extract static metadata, but complex or dynamically generated values might not be fully captured without executing the file in a controlled environment.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that the path to your sdist, wheel, or project directory is correct and accessible. Use `pathlib.Path` to construct paths robustly.","cause":"The path provided to `get_metadata` does not point to an existing file or directory.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_package-1.0.0.tar.gz'"},{"fix":"Ensure the input path points to a valid `.tar.gz` (sdist), `.whl` (wheel), or a directory containing standard Python project configuration files (`pyproject.toml` or `setup.py`).","cause":"The provided file or directory is not a recognized Python distribution artifact (sdist/wheel) and does not contain `pyproject.toml` or `setup.py` for direct source metadata extraction.","error":"metadata_please.exceptions.InvalidMetadata: Could not extract metadata from provided path. No pyproject.toml, setup.py, or recognized artifact found."},{"fix":"Consult Python's Core metadata specifications or `metadata-please` documentation to understand available fields. If a field is missing, it might not be standard or could not be parsed.","cause":"Attempting to access a metadata field that is not part of the standard Python core metadata or not extracted by the library. The `DistributionMetadata` object exposes common fields like `name`, `version`, `summary`, etc..","error":"AttributeError: 'DistributionMetadata' object has no attribute 'unsupported_field'"}]}