Metadata Please

0.2.1 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

from metadata_please import get_metadata
from pathlib import Path
import tempfile
import shutil

# Create dummy files for demonstration
def create_dummy_sdist(path):
    path.mkdir(parents=True, exist_ok=True)
    with open(path / 'setup.py', 'w') as f:
        f.write("from setuptools import setup; setup(name='dummy_sdist', version='0.1.0')")
    # In a real scenario, you'd run `python setup.py sdist`
    # For this example, we'll just point to the dir as if it were an sdist source

def create_dummy_pyproject_toml(path):
    path.mkdir(parents=True, exist_ok=True)
    with open(path / 'pyproject.toml', 'w') as f:
        f.write('[project]\nname = "dummy-toml"\nversion = "0.2.0"')

with tempfile.TemporaryDirectory() as tmpdir:
    tmp_path = Path(tmpdir)

    # Example 1: Project directory with setup.py (simplified as source dir)
    sdist_source_dir = tmp_path / "dummy_sdist_project"
    create_dummy_sdist(sdist_source_dir)
    metadata_sdist = get_metadata(sdist_source_dir)
    print(f"sdist project Name: {metadata_sdist.name}, Version: {metadata_sdist.version}")

    # Example 2: Project directory with pyproject.toml
    pyproject_source_dir = tmp_path / "dummy_toml_project"
    create_dummy_pyproject_toml(pyproject_source_dir)
    metadata_toml = get_metadata(pyproject_source_dir)
    print(f"pyproject.toml project Name: {metadata_toml.name}, Version: {metadata_toml.version}")

    # Note: For actual .tar.gz (sdist) or .whl (wheel) files,
    # you would replace the paths with your actual artifact files.
    # Creating real sdist/wheel files dynamically for a quickstart is complex.
    # The library is designed to work with these file types directly.
    # Example (conceptual for artifact files):
    # real_sdist_path = Path("path/to/your_package-1.0.0.tar.gz")
    # metadata_real_sdist = get_metadata(real_sdist_path)
    # print(f"Real sdist Name: {metadata_real_sdist.name}")

view raw JSON →