pkginfo2
raw JSON → 30.1.0 verified Fri May 01 auth: no python
Query metadata from sdists, bdists, and installed packages. A safer fork of pkginfo that avoids arbitrary imports and eval. Current version 30.1.0, released 2025-04. Maintained by AboutCode.org.
pip install pkginfo2 Common errors
error ModuleNotFoundError: No module named 'pkginfo' ↓
cause Attempting to use old pkginfo package under the name pkginfo2.
fix
Install pkginfo2: pip install pkginfo2
error AttributeError: 'NoneType' object has no attribute 'name' ↓
cause get_metadata() returned None for a .whl file without METADATA.
fix
Check return value: metadata = get_metadata('file.whl'); if metadata is None: handle error
error ImportError: cannot import name 'get_metadata' from 'pkginfo2' ↓
cause Old version of pkginfo2 (<30.0.0) may not include get_metadata.
fix
Upgrade to latest: pip install --upgrade pkginfo2
Warnings
breaking pkginfo2 is a separate fork; do not mix imports with the original pkginfo. The API is similar but not identical. ↓
fix Replace 'from pkginfo import ...' with 'from pkginfo2 import ...'
gotcha get_metadata() with a .whl file may return None if the wheel is not a valid zip or lacks METADATA file. ↓
fix Check for None before accessing attributes:
metadata = get_metadata('pkg.whl')
if metadata is None:
raise ValueError('Could not read metadata')
breaking Python 3.10+ only. Older Python versions are not supported. ↓
fix Upgrade to Python 3.10 or later.
Imports
- get_metadata wrong
from pkginfo import get_metadatacorrectfrom pkginfo2 import get_metadata - UnpackedSDist
from pkginfo2 import UnpackedSDist
Quickstart
from pkginfo2 import get_metadata
# Get metadata from a source distribution
metadata = get_metadata('pkginfo2-30.1.0.tar.gz')
print(metadata.name, metadata.version)
# Get metadata from an installed package
from pkginfo2.installed import Installed
inst = Installed('pkginfo2')
print(inst.name, inst.version)
# Use environment variable for a file path
import os
path = os.environ.get('PKGINFO2_FILE', 'pkginfo2-30.1.0.tar.gz')
metadata = get_metadata(path)
print(metadata.name, metadata.version)