importlib.metadata queries metadata recorded by the installer. This differs from importing a module: a distribution name and an import name may not match.

Practical example

from importlib.metadata import PackageNotFoundError, version

try:
    installed = version("pip")
except PackageNotFoundError:
    installed = None

print(installed)

Versions and expected failures

Use version() when the installed version matters and handle PackageNotFoundError. Do not use plain string comparison for compatibility decisions; version parsing has dedicated rules.

Entry points enable extensions

Entry points discover plugins declared by packages. Filter the expected group and load only trusted extensions, because load() imports and executes environment code.

Keep learning

Continue with PIP Python: Complete Guide to Managing Dependencies and Python pyproject.toml Guide for Applications and Libraries. A official Python documentation, accessed July 22, 2026, documents the API and behavior across versions.