Registry / serialization / metadata-please

metadata-please

JSON →
library0.2.1pypypi✓ verified 83d ago

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.

pip install metadata-please
INSTALL
IMPORT
SIG · METADATA-PLEASE
M
metadata-please
serializationpythonv0.2.1
Install
1.8s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from_source_checkout
from metadata_please import from_source_checkout
from metadata_please import get_metadata
from_wheel
from metadata_please import from_wheel
from_tar_sdist
from metadata_please import from_tar_sdist

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}")
Debug
Known issues
gotchaThe 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`).
fix
For comprehensive runtime introspection of *installed* packages, consider `importlib.metadata` (standard library for Python 3.8+ or `importlib_metadata` backport).
affects: All versions
gotchaDirect 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.
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.
affects: >=0.2.0
Upgrade
Version history
0.2.1latest on PyPI · released Nov 15, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
metadata-please — pip install metadata-please · libregistry