pip-api: Unofficial Importable pip API

0.0.34 · active · verified Thu Apr 09

pip-api is an unofficial Python library providing a programmatic interface to pip's functionality. It allows developers to inspect installed packages, run pip commands, and manage package metadata directly from Python code. The current version is 0.0.34. Due to its nature of wrapping pip's internal APIs, its release cadence is closely tied to pip's updates and internal changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to list currently installed packages and how to execute a basic `pip` command using `pip-api`.

from pip_api import installed_packages, run

# List all installed packages
print("Installed Packages:")
for package_name, package_info in installed_packages().items():
    print(f"  {package_info.name}=={package_info.version}")

# Example of running a pip command (e.g., showing details of a package)
# Note: This executes pip directly and can have side effects.
# Use a package that's likely installed, like 'pip' itself.
try:
    # 'run' returns a (stdout, stderr) tuple
    stdout, stderr = run(['show', 'pip'])
    print("\n'pip show pip' output:\n" + stdout.decode('utf-8'))
except Exception as e:
    print(f"Error running pip command: {e}")

view raw JSON →