Registry / devops / pip-api

pip-api

JSON →
library0.0.34pypypi✓ verified 24d ago

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.

pip install pip-api
INSTALL
IMPORT
SIG · PIP-API
P
pip-api
devopspythonv0.0.34
Install
1.6s avg
Import
520ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.34 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.570s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.470s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

installed_distributions
from pip_api import installed_distributions
from pip_api import installed_packages
parse_requirements
from pip_api import parse_requirements
Requirement
from pip_api import Requirement

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}")
Debug
Known issues
breakingSupport for Python 3.7 was dropped in version 0.0.34. Users on Python 3.7 or older will need to upgrade their Python version or use an older `pip-api` release.
fix
Upgrade to Python 3.8 or newer, or pin `pip-api<0.0.34`.
affects: 0.0.34+
gotcha`pip-api` is an *unofficial* API and relies on `pip`'s internal structure, which is not guaranteed to be stable. Updates to `pip` itself can introduce breaking changes for `pip-api` without warning, potentially requiring `pip-api` updates or causing unexpected behavior.
fix
Monitor `pip-api` releases for compatibility with new `pip` versions and thoroughly test your application after `pip` or `pip-api` upgrades.
affects: All versions
gotchaThe `pip_api.run()` function directly executes pip commands, which can have side effects such as installing, uninstalling, or upgrading packages in the current environment. This is not a sandboxed operation.
fix
Exercise caution when using `pip_api.run()` with commands that modify the environment. Consider running in isolated or virtual environments for sensitive operations.
affects: All versions
gotchaThe `pip_api.installed_packages()` function might incur performance overhead due to parsing package metadata. While `pip-api` aims to be efficient, repeated calls in performance-critical loops might be slow.
fix
Cache the result of `installed_packages()` if you need to access package information multiple times within a short period or in performance-sensitive sections of your code.
affects: All versions
Upgrade
Version history
0.0.34latest on PyPI · released Jul 9, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Amazon
1
Resources
pip-api — pip install pip-api · libregistry