importlib-metadata

9.0.0 · active · verified Sat Mar 28

importlib-metadata provides third-party access to the functionality of the stdlib importlib.metadata module, including features backported from future Python versions. It allows reading installed package metadata such as version strings, entry points, file lists, and requirements. Current version is 9.0.0 (requires Python >=3.10). New features are introduced here first and later merged into CPython; releases track CPython closely with frequent minor/patch releases.

Warnings

Install

Imports

Quickstart

Retrieve package version, metadata fields, entry points, and the import-name-to-distribution mapping using the modern importlib_metadata API.

from importlib_metadata import version, metadata, entry_points, packages_distributions, PackageNotFoundError

# Get version string
try:
    ver = version('pip')
    print(f'pip version: {ver}')
except PackageNotFoundError:
    print('pip is not installed')

# Read metadata fields
meta = metadata('pip')
print('Author:', meta['Author-email'])
print('Requires-Python:', meta['Requires-Python'])

# List console_scripts entry points (v5.0+ API)
eps = entry_points(group='console_scripts')
for ep in eps:
    print(f'  {ep.name} -> {ep.value}')

# Map import names to distribution names
pkg_to_dist = packages_distributions()
print('importlib_metadata dist(s):', pkg_to_dist.get('importlib_metadata'))

view raw JSON →