pkginfo

raw JSON →
1.12.1.2 verified Tue May 12 auth: no python install: verified quickstart: verified

pkginfo is a Python library providing an API for querying metadata from Python package distributions. It can extract information from source distributions (sdists), binary distributions (bdists, including wheels), and installed packages by inspecting PKG-INFO, EGG-INFO, or dist-info files/directories. The library is actively maintained, with version 1.12.1.2 released in February 2025, and maintains a consistent release cadence.

pip install pkginfo
error ModuleNotFoundError: No module named 'pkginfo'
cause The `pkginfo` library is not installed in the Python environment where the code is being executed.
fix
Install the pkginfo library using pip: pip install pkginfo
error KeyError: 'No metadata except PKG-INFO is available'
cause This error typically occurs when a tool (like pip or setuptools, which may internally use or rely on similar metadata parsing logic as `pkginfo`) attempts to read package metadata, but only finds a basic `PKG-INFO` file without additional expected metadata, or the metadata is malformed/incomplete.
fix
Ensure the package being analyzed has correctly generated metadata files. If you are building a package, verify setup.py or pyproject.toml correctly defines metadata. If consuming, try updating the package or the tools used for installation/inspection (e.g., pip install --upgrade setuptools pip).
error pkginfo: ERROR: pkginfo file is corrupt or missing.
cause The `pkginfo` library or a related utility failed to locate or parse the `PKG-INFO` file within a distribution, indicating the file is either absent, unreadable, or contains syntax errors.
fix
Verify the integrity and presence of the PKG-INFO file within the distribution. This might involve inspecting the .egg-info or .dist-info directory, or the contents of an sdist/wheel archive. If you created the package, ensure your build process correctly generates this file.
breaking Older versions of `pkginfo` (specifically pre-1.10.0) may not correctly parse or fully support newer PEP metadata versions (e.g., Metadata-Version 2.3 and higher) used by modern Python packages, leading to errors or incomplete information.
fix Upgrade to `pkginfo` version 1.10.0 or newer: `pip install --upgrade pkginfo`.
breaking Support for Python 2.7 was officially dropped in version 1.90. Users on Python 2.7 will encounter compatibility issues.
fix Migrate your project to Python 3.8 or newer, which is the minimum supported version.
gotcha The `pkginfo2` fork was created to address concerns regarding the original `pkginfo`'s historical potential for 'arbitrary imports and eval' when parsing package metadata. While `pkginfo` has evolved, users with stringent security requirements or those processing untrusted package metadata should be aware of this historical context and consider their threat model.
fix Ensure you are using the latest `pkginfo` version. For critical security contexts, carefully audit the package parsing mechanisms or consider sandboxing the operation.
gotcha When using `pkginfo.Installed` to query an installed package, the package's `.egg-info` or `.dist-info` metadata directory must be discoverable (e.g., located inside the package or adjacent to it). If metadata is not in a standard location, `pkginfo` may fail to find it.
fix Verify that the target installed package has its metadata (`.egg-info` or `.dist-info`) in a standard, discoverable location relative to the package files.
gotcha When using `pkginfo.SDist` or `pkginfo.Wheel` to process distribution files, the provided path must point to an actual, existing sdist or wheel file respectively. If the file does not exist at the specified path, `pkginfo` will not be able to process it, typically resulting in a `FileNotFoundError` or similar indication of missing input.
fix Ensure the path provided to `pkginfo.SDist` or `pkginfo.Wheel` is correct and that the target distribution file exists at that location before attempting to parse it.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.10s 18.1M
3.10 slim (glibc) - - 0.07s 19M
3.11 alpine (musl) - - 0.10s 20.0M
3.11 slim (glibc) - - 0.15s 20M
3.12 alpine (musl) - - 0.12s 11.9M
3.12 slim (glibc) - - 0.09s 12M
3.13 alpine (musl) - - 0.06s 11.5M
3.13 slim (glibc) - - 0.07s 12M
3.9 alpine (musl) - - 0.10s 17.6M
3.9 slim (glibc) - - 0.11s 18M

This quickstart demonstrates how to extract metadata from different package distribution types. It shows how to initialize `SDist`, `Wheel`, and `Installed` objects with appropriate paths or package names, and then access common metadata attributes like `name`, `version`, and `metadata_version`.

import os
from pkginfo import SDist, Wheel, Installed

# Example for a source distribution (sdist)
# Assuming 'example_package-1.0.tar.gz' exists in the current directory
# For a real-world use, replace with an actual sdist path
sdist_path = 'path/to/your/package-1.0.tar.gz'
if os.path.exists(sdist_path):
    sdist_info = SDist(sdist_path)
    print(f"SDist Name: {sdist_info.name}, Version: {sdist_info.version}, Metadata-Version: {sdist_info.metadata_version}")
else:
    print(f"SDist example skipped: {sdist_path} not found. Please provide a valid sdist file.")

# Example for a wheel distribution
# Assuming 'example_package-1.0-py3-none-any.whl' exists
wheel_path = 'path/to/your/package-1.0-py3-none-any.whl'
if os.path.exists(wheel_path):
    wheel_info = Wheel(wheel_path)
    print(f"Wheel Name: {wheel_info.name}, Version: {wheel_info.version}, Metadata-Version: {wheel_info.metadata_version}")
else:
    print(f"Wheel example skipped: {wheel_path} not found. Please provide a valid wheel file.")

# Example for an installed package (e.g., 'pip')
try:
    installed_info = Installed('pip')
    print(f"Installed Name: {installed_info.name}, Version: {installed_info.version}, Metadata-Version: {installed_info.metadata_version}")
except Exception as e:
    print(f"Could not get info for 'pip' (maybe not installed or metadata not found): {e}")