pkginfo

1.12.1.2 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →