Skip to main content

callable-pip

callable-pip provides a drop-in replacement for pip.main() and support for monkey-patching pip.main via a known-dangerous method.

pip.main() has never been a publicly supported API for pip, but it has often been used as such. This tiny package is meant to cover the gap and ease people’s transitions to new usage.

Drop-in Replacement for pip.main

This usage is always guaranteed to work on any supported python version with any functioning version of pip.

Instead of pip.main(...), use this method instead:

import callable_pip
callable_pip.main('install', '--upgrade', 'setuptools')

If you are writing a python program, you can just use callable_pip.main() yourself. This is the only guaranteed-safe usage.

Patching pip.main

callable-pip provides a patch which adds pip.main() back to pip, but which is dangerous and known not to work on some versions of pip:

import callable_pip
callable_pip.dangerous_patch()
...
import pip
pip.main('--version')  # actually invokes callable_pip.main()

If you have dependencies which use pip.main, you can call callable_pip.dangerous_patch() yourself and it will usually work.

dangerous_patch is so-named because it is not guaranteed to work on all pip versions and it is dangerous. Avoid it when possible.

Patching Without Control of Source

You may be a consumer of packages which use pip.main() in a context where you cannot modify or do not own any of the source. These techniques may help you.

More details on sitecustomize.py and .pth files can be found in the Python documentation: https://docs.python.org/3/library/site.html

Remember to remove these patches if you uninstall callable_pip, or Python will fail to start.

Applying the Patch With sitecustomize.py

sitecustomize.py can exist anywhere in the PYTHONPATH, including the directory where python is invoked.

Add a sitecustomize.py with the following content, or append it to an existing sitecustomize.py:

import callable_pip
callable_pip.dangerous_patch()

Applying the Patch With a .pth File

The .pth file can have any name you want, but must be installed in the site-packages directory. It may therefore require root or other elevated privileges to add.

Add a file, e.g. callable_pip.pth, with the following content:

import callable_pip; callable_pip.dangerous_patch()

Documentation

All documentation is in this readme doc.

Bug and Issue Reports

Submit all bug reports and issues here: https://github.com/sirosen/callable-pip/issues

Changelog

2.0.0

Update to pyproject.toml with flit-core for package builds.

Defer import of subprocess until it is needed.

1.0.0

Improved docs, releasing as v1.0 Production after some testing and validation. No code changes from v0.1.0

0.1.0

Initial version

Metadata

Release files for callable-pip 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for callable-pip 2.0.0
File Size Uploaded
callable_pip-2.0.0.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for callable-pip 2.0.0
File Interpreter ABI Platform
callable_pip-2.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 7.3 kB

Release files / callable_pip-2.0.0.tar.gz

Download URL callable_pip-2.0.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1bc39542cd0910956b89f00d77f070ceb060f225ac3ab3818749bb7db4d60e17
BLAKE2b-256 checksum
How to use checksums
cb63b9e12142ead54a999829adfdfc819f5628871542340320c34b19aab44fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release files / callable_pip-2.0.0-py2.py3-none-any.whl

Download URL callable_pip-2.0.0-py2.py3-none-any.whl
Size 3.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
778eb73d239120d9380127db1d9b1bf0faa1fe6d2a254f130c9b9a7db15c10c4
BLAKE2b-256 checksum
How to use checksums
0b9fb4ec91d8c241a13d2f40742d149af6b16c1c0dcc8faf68c95b59788c090e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page