{"id":1626,"library":"pip-api","title":"pip-api: Unofficial Importable pip API","description":"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.","status":"active","version":"0.0.34","language":"en","source_language":"en","source_url":"https://github.com/di/pip-api","tags":["pip","packaging","package management","cli","utility"],"install":[{"cmd":"pip install pip-api","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Used to get a dictionary of all installed packages.","symbol":"installed_packages","correct":"from pip_api import installed_packages"},{"note":"Used to execute arbitrary pip commands programmatically.","symbol":"run","correct":"from pip_api import run"}],"quickstart":{"code":"from pip_api import installed_packages, run\n\n# List all installed packages\nprint(\"Installed Packages:\")\nfor package_name, package_info in installed_packages().items():\n    print(f\"  {package_info.name}=={package_info.version}\")\n\n# Example of running a pip command (e.g., showing details of a package)\n# Note: This executes pip directly and can have side effects.\n# Use a package that's likely installed, like 'pip' itself.\ntry:\n    # 'run' returns a (stdout, stderr) tuple\n    stdout, stderr = run(['show', 'pip'])\n    print(\"\\n'pip show pip' output:\\n\" + stdout.decode('utf-8'))\nexcept Exception as e:\n    print(f\"Error running pip command: {e}\")","lang":"python","description":"This quickstart demonstrates how to list currently installed packages and how to execute a basic `pip` command using `pip-api`."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer, or pin `pip-api<0.0.34`.","message":"Support 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.","severity":"breaking","affected_versions":"0.0.34+"},{"fix":"Monitor `pip-api` releases for compatibility with new `pip` versions and thoroughly test your application after `pip` or `pip-api` upgrades.","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Exercise caution when using `pip_api.run()` with commands that modify the environment. Consider running in isolated or virtual environments for sensitive operations.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}