• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 27 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An unofficial, importable pip API

GitHub - License PyPI - Python Version PyPI - Package Version Conda - Platform Conda (channel only) Conda Recipe

Since pip is a command-line-tool, it does not have an official, supported, importable API.

However, this does not mean that people haven't tried to import pip, usually to end up with much headache when pip's maintainers do routine refactoring.

Goal

The goal of this project is to provide an importable pip API, which is fully compliant with the recommended method of using pip from your program.

How? By providing an importable API that wraps command-line calls to pip, this library can be used as a drop-in replacement for existing uses of pip's internal API.

Scope

This goal means that any new API added here must have the following equivalents:

  • some internal pip API (or combination of internal APIs)
  • some CLI calls (or combination of CLI calls)

Any functionality that is not currently possible from internal pip API or CLI calls is out of scope.

Installation

You can install pip-api with either pip or with conda.

With pip:

python -m pip install pip-api

With conda:

conda install -c conda-forge pip-api

Supported Commands

Not all commands are supported in all versions of pip and on all platforms. If the command you are trying to use is not compatible, pip_api will raise a pip_api.exceptions.Incompatible exception for your program to catch.

Available with all pip versions:

  • pip_api.version()

    Returns the pip version as a string, e.g. "9.0.1"

  • pip_api.installed_distributions(local=False)

    Returns a list of all installed distributions as a Distribution object with the following attributes:

    • Distribution.name (string): The name of the installed distribution
    • Distribution.version (packaging.version.Version): The version of the installed distribution
    • Distribution.location (string): The location of the installed distribution
    • Distribution.editable (bool): Whether the distribution is editable or not Optionally takes a local parameter to filter out globally-installed packages
  • pip_api.parse_requirements(filename, options=None, include_invalid=False, strict_hashes=False)

    Takes a path to a filename of a Requirements file. Returns a mapping from package name to a pip_api.Requirement object (subclass of packaging.requirements.Requirement) with the following attributes:

    • Requirement.name (string): The name of the requirement.
    • Requirement.extras (set): A set of extras that the requirement specifies.
    • Requirement.specifier (packaging.specifiers.SpecifierSet): A SpecifierSet of the version specified by the requirement.
    • Requirement.marker (packaging.markers.Marker): A Marker of the marker for the requirement. Can be None.
    • Requirement.hashes (dict): A mapping of hashes for the requirement, corresponding to --hash=... options.
    • Requirement.editable (bool): Whether the requirement is editable, corresponding to -e ...
    • Requirement.filename (str): The filename that the requirement originates from.
    • Requirement.lineno (int): The source line that the requirement was parsed from.

    Optionally takes an options parameter to override the regex used to skip requirements lines. Optionally takes an include_invalid parameter to return an UnparsedRequirement in the event that a requirement cannot be parsed correctly. Optionally takes a strict_hashes parameter to require that all requirements have associated hashes.

Available with pip>=8.0.0:

  • pip_api.hash(filename, algorithm='sha256')

    Returns the resulting as a string. Valid algorithm parameters are 'sha256', 'sha384', and 'sha512'

Available with pip>=19.2:

  • pip_api.installed_distributions(local=False, paths=[])

    As described above, but with an extra optional paths parameter to provide a list of locations to look for installed distributions. Attempting to use the paths parameter with pip<19.2 will result in a PipError.

Use cases

This library is in use by a number of other tools, including:

  • pip-audit, to analyze dependencies for known vulnerabilities
  • pytest-reqs, to compare requirements files with test dependencies
  • hashin, to add hash pinning to requirements files
  • ...and many more.

More Repositories

1

vladiate

A strict validation tool for CSV files
Python
90
star
2

divspl

Dustin Ingram's Very Special Programming Language
Python
54
star
3

pyreadiness

Python support graph for specific Python versions for the most popular Python packages
HTML
41
star
4

screenshare

Super-simple screen sharing with nothing but Python and Flask.
HTML
41
star
5

markdown-description-example

Markdown project descriptions on PyPI!
Python
40
star
6

flask-accept

Custom Accept header routing support for Flask
Python
39
star
7

mrfh

Multiprocess Rotating File Handler
Python
36
star
8

pytest-reqs

py.test plugin for checking requirements files
Python
25
star
9

talks

Repository of talks I've given
Python
19
star
10

calver

Setuptools extension for CalVer package versions
Python
16
star
11

vendy

Vendy is a tool for vendoring third-party packages into your project.
Python
15
star
12

astro-pybrain

Detecting Asteroids with Neural Networks
Python
12
star
13

pivotallabels

Chrome extension for Pivotal Tracker which allows you to set custom colors for label names.
JavaScript
10
star
14

id

A tool for generating OIDC identities
Python
9
star
15

corvid

An opinionated simple static site generator
Python
9
star
16

tinyhouse

๐Ÿ  A tiny, zero-dependency Python Python Package Index
Python
8
star
17

all-of-pypi

This project installs all of PyPI.
Python
7
star
18

astro-tf

Detecting Asteroids with TensorFlow
Groff
6
star
19

vintage-python

Base images for vintage Python distributions
Dockerfile
5
star
20

repyt

Automatically re-run Python commands when files change.
Python
5
star
21

ruffruffs

Barkyipyipruff grr woofwoof
Python
4
star
22

packaging_legacy

This library provides support for "legacy" Python Packaging functionality removed from https://github.com/pypa/packaging.
Python
4
star
23

di.github.com

Repo which powers my personal website.
HTML
4
star
24

gh-action-build

Shell
3
star
25

asteroid-detect

Proof-of-concept tools to detect asteroids in satellite images from the Sloan Digital Sky Survey.
Python
3
star
26

mcmuc

A distributed application-layer protocol which provides multi-user chat over multicast.
Java
3
star
27

daywrite

Write better, every day.
JavaScript
2
star
28

ppa

Scraper for Philadelphia Parking Authority data.
Python
2
star
29

doneit

Daily Task Management & Daily Digest System
Python
2
star
30

xforhumans

Find software for your species
JavaScript
2
star
31

sheriff

Philadelphia sheriff sales
Python
2
star
32

phillyradio

๐Ÿ“ป Pure-CSS3/JS HTML5 old-timey radio FM-dial jawn.
CSS
2
star
33

slack-irc-heroku-bridge

IRC Bouncer and bridge to Slack hosted on Heroku
2
star
34

daywrite-node

Write better, every day.
JavaScript
2
star
35

coryingram.com

HTML
1
star
36

identity-token-test

1
star
37

school

My school work, circa 2006-2014
TeX
1
star
38

landmash

Landmark Theatres Movie Listing Mashup
Python
1
star
39

node-sample-dependency

Shell
1
star
40

node-sample-function

Shell
1
star
41

dustinandsheadotcom.biz

HTML
1
star
42

java-sample-dependency

Java
1
star
43

travis-test

Python
1
star
44

matcher

PSF Donation Matcher
Python
1
star
45

python-sample-function

Shell
1
star
46

ahoy

AHOY is an event-based simulation environment designed to test networked multi-agent systems.
Python
1
star
47

euler

Repo of my solutios to Project Euler in Scheme.
Scheme
1
star
48

python-sample-dependency

Shell
1
star
49

pelican-test

Python
1
star
50

java-sample-function

Java
1
star