<!--- BADGES: START --->
[![GitHub - License](https://img.shields.io/github/license/di/pip-api?logo=github&style=flat&color=green)][#github-license]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pip-api?logo=pypi&style=flat&color=blue)][#pypi-package]
[![PyPI - Package Version](https://img.shields.io/pypi/v/pip-api?logo=pypi&style=flat&color=orange)][#pypi-package]
[![Conda - Platform](https://img.shields.io/conda/pn/conda-forge/pip-api?logo=anaconda&style=flat)][#conda-forge-package]
[![Conda (channel only)](https://img.shields.io/conda/vn/conda-forge/pip-api?logo=anaconda&style=flat&color=orange)][#conda-forge-package]
[![Conda Recipe](https://img.shields.io/static/v1?logo=conda-forge&style=flat&color=green&label=recipe&message=pip-api)][#conda-forge-feedstock]
[#github-license]: https://github.com/di/pip-api/blob/master/LICENSE
[#pypi-package]: https://pypi.org/project/pip-api/
[#conda-forge-package]: https://anaconda.org/conda-forge/pip-api
[#conda-forge-feedstock]: https://github.com/conda-forge/pip-api-feedstock
<!--- BADGES: END --->
Since [`pip`](https://pypi.org/p/pip) is a command-line-tool, [it does not have
an official, supported, _importable_
API](https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program).
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**:
```sh
python -m pip install pip-api
```
**With conda**:
```sh
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`](https://packaging.pypa.io/en/latest/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`](https://packaging.pypa.io/en/latest/requirements/#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`](https://packaging.pypa.io/en/latest/specifiers/#packaging.specifiers.SpecifierSet)): A `SpecifierSet` of the version specified by the requirement.
> * `Requirement.marker` ([`packaging.markers.Marker`](https://packaging.pypa.io/en/latest/markers/#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`](https://pypi.org/project/pip-audit/), to analyze dependencies for known vulnerabilities
* [`pytest-reqs`](https://pypi.org/project/pytest-reqs), to compare requirements files with test dependencies
* [`hashin`](https://pypi.org/project/hashin/), to add hash pinning to requirements files
* ...and many more.
Raw data
{
"_id": null,
"home_page": "http://github.com/di/pip-api",
"name": "pip-api",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Dustin Ingram",
"author_email": "di@python.org",
"download_url": "https://files.pythonhosted.org/packages/b9/f1/ee85f8c7e82bccf90a3c7aad22863cc6e20057860a1361083cd2adacb92e/pip_api-0.0.34.tar.gz",
"platform": null,
"description": "\n<!--- BADGES: START --->\n[![GitHub - License](https://img.shields.io/github/license/di/pip-api?logo=github&style=flat&color=green)][#github-license]\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pip-api?logo=pypi&style=flat&color=blue)][#pypi-package]\n[![PyPI - Package Version](https://img.shields.io/pypi/v/pip-api?logo=pypi&style=flat&color=orange)][#pypi-package]\n[![Conda - Platform](https://img.shields.io/conda/pn/conda-forge/pip-api?logo=anaconda&style=flat)][#conda-forge-package]\n[![Conda (channel only)](https://img.shields.io/conda/vn/conda-forge/pip-api?logo=anaconda&style=flat&color=orange)][#conda-forge-package]\n[![Conda Recipe](https://img.shields.io/static/v1?logo=conda-forge&style=flat&color=green&label=recipe&message=pip-api)][#conda-forge-feedstock]\n\n[#github-license]: https://github.com/di/pip-api/blob/master/LICENSE\n[#pypi-package]: https://pypi.org/project/pip-api/\n[#conda-forge-package]: https://anaconda.org/conda-forge/pip-api\n[#conda-forge-feedstock]: https://github.com/conda-forge/pip-api-feedstock\n<!--- BADGES: END --->\n\nSince [`pip`](https://pypi.org/p/pip) is a command-line-tool, [it does not have\nan official, supported, _importable_\nAPI](https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program).\n\nHowever, this does not mean that people haven't tried to `import pip`, usually\nto end up with much headache when `pip`'s maintainers do routine refactoring.\n\n## Goal\nThe goal of this project is to provide an importable `pip` API, which is _fully\ncompliant_ with the recommended method of using `pip` from your program.\n\nHow? By providing an importable API that wraps command-line calls to `pip`,\nthis library can be used as a drop-in replacement for existing uses of `pip`'s\ninternal API.\n\n### Scope\nThis goal means that any new API added here must have the following\nequivalents:\n\n- some internal `pip` API (or combination of internal APIs)\n- some CLI calls (or combination of CLI calls)\n\nAny functionality that is not currently possible from internal `pip` API or\nCLI calls is out of scope.\n\n## Installation\n\nYou can install `pip-api` with either `pip` or with `conda`.\n\n**With pip**:\n\n```sh\npython -m pip install pip-api\n```\n\n**With conda**:\n\n```sh\nconda install -c conda-forge pip-api\n```\n\n## Supported Commands\n\nNot all commands are supported in all versions of `pip` and on all platforms.\nIf the command you are trying to use is not compatible, `pip_api` will raise a\n`pip_api.exceptions.Incompatible` exception for your program to catch.\n\n### Available with all `pip` versions:\n* `pip_api.version()`\n > Returns the `pip` version as a string, e.g. `\"9.0.1\"`\n\n* `pip_api.installed_distributions(local=False)`\n > Returns a list of all installed distributions as a `Distribution` object with the following attributes:\n > * `Distribution.name` (`string`): The name of the installed distribution\n > * `Distribution.version` ([`packaging.version.Version`](https://packaging.pypa.io/en/latest/version/#packaging.version.Version)): The version of the installed distribution\n > * `Distribution.location` (`string`): The location of the installed distribution\n > * `Distribution.editable` (`bool`): Whether the distribution is editable or not\n > Optionally takes a `local` parameter to filter out globally-installed packages\n\n* `pip_api.parse_requirements(filename, options=None, include_invalid=False, strict_hashes=False)`\n > 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`](https://packaging.pypa.io/en/latest/requirements/#packaging.requirements.Requirement)) with the following attributes:\n > * `Requirement.name` (`string`): The name of the requirement.\n > * `Requirement.extras` (`set`): A set of extras that the requirement specifies.\n > * `Requirement.specifier` ([`packaging.specifiers.SpecifierSet`](https://packaging.pypa.io/en/latest/specifiers/#packaging.specifiers.SpecifierSet)): A `SpecifierSet` of the version specified by the requirement.\n > * `Requirement.marker` ([`packaging.markers.Marker`](https://packaging.pypa.io/en/latest/markers/#packaging.markers.Marker)): A `Marker` of the marker for the requirement. Can be `None`.\n > * `Requirement.hashes` (`dict`): A mapping of hashes for the requirement, corresponding to `--hash=...` options.\n > * `Requirement.editable` (`bool`): Whether the requirement is editable, corresponding to `-e ...`\n > * `Requirement.filename` (`str`): The filename that the requirement originates from.\n > * `Requirement.lineno` (`int`): The source line that the requirement was parsed from.\n >\n > Optionally takes an `options` parameter to override the regex used to skip requirements lines.\n > Optionally takes an `include_invalid` parameter to return an `UnparsedRequirement` in the event that a requirement cannot be parsed correctly.\n > Optionally takes a `strict_hashes` parameter to require that all requirements have associated hashes.\n\n### Available with `pip>=8.0.0`:\n* `pip_api.hash(filename, algorithm='sha256')`\n > Returns the resulting as a string.\n > Valid `algorithm` parameters are `'sha256'`, `'sha384'`, and `'sha512'`\n\n### Available with `pip>=19.2`:\n* `pip_api.installed_distributions(local=False, paths=[])`\n > 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`.\n\n## Use cases\nThis library is in use by a number of other tools, including:\n* [`pip-audit`](https://pypi.org/project/pip-audit/), to analyze dependencies for known vulnerabilities\n* [`pytest-reqs`](https://pypi.org/project/pytest-reqs), to compare requirements files with test dependencies\n* [`hashin`](https://pypi.org/project/hashin/), to add hash pinning to requirements files\n* ...and many more.\n",
"bugtrack_url": null,
"license": null,
"summary": "An unofficial, importable pip API",
"version": "0.0.34",
"project_urls": {
"Homepage": "http://github.com/di/pip-api"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "91f7ebf5003e1065fd00b4cbef53bf0a65c3d3e1b599b676d5383ccb7a8b88ba",
"md5": "0abb34bd1f77d39320145d228f510cd9",
"sha256": "8b2d7d7c37f2447373aa2cf8b1f60a2f2b27a84e1e9e0294a3f6ef10eb3ba6bb"
},
"downloads": -1,
"filename": "pip_api-0.0.34-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0abb34bd1f77d39320145d228f510cd9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 120369,
"upload_time": "2024-07-09T20:32:29",
"upload_time_iso_8601": "2024-07-09T20:32:29.099333Z",
"url": "https://files.pythonhosted.org/packages/91/f7/ebf5003e1065fd00b4cbef53bf0a65c3d3e1b599b676d5383ccb7a8b88ba/pip_api-0.0.34-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b9f1ee85f8c7e82bccf90a3c7aad22863cc6e20057860a1361083cd2adacb92e",
"md5": "f5ba7e74d1d48b6beec0451ab3896959",
"sha256": "9b75e958f14c5a2614bae415f2adf7eeb54d50a2cfbe7e24fd4826471bac3625"
},
"downloads": -1,
"filename": "pip_api-0.0.34.tar.gz",
"has_sig": false,
"md5_digest": "f5ba7e74d1d48b6beec0451ab3896959",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 123017,
"upload_time": "2024-07-09T20:32:30",
"upload_time_iso_8601": "2024-07-09T20:32:30.641488Z",
"url": "https://files.pythonhosted.org/packages/b9/f1/ee85f8c7e82bccf90a3c7aad22863cc6e20057860a1361083cd2adacb92e/pip_api-0.0.34.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-09 20:32:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "di",
"github_project": "pip-api",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pip-api"
}