pip-api


Namepip-api JSON
Version 0.0.33 PyPI version JSON
download
home_pagehttp://github.com/di/pip-api
SummaryAn unofficial, importable pip API
upload_time2024-02-15 22:29:39
maintainer
docs_urlNone
authorDustin Ingram
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<!--- 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": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Dustin Ingram",
    "author_email": "di@python.org",
    "download_url": "https://files.pythonhosted.org/packages/ae/28/da6bd24c67a6d52a535fa8b888b1495d1d2ec7b2705a45ce5d351a3047bb/pip-api-0.0.33.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": "",
    "summary": "An unofficial, importable pip API",
    "version": "0.0.33",
    "project_urls": {
        "Homepage": "http://github.com/di/pip-api"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5a5ecff8712be393a0d9c221e036082163b69d491f99b7772d37b935cb078d6",
                "md5": "6f22dfd0adf4857d53e9ed42cedbb5f9",
                "sha256": "b8d6eb5a87d3a9e112a20a8e9d24a6fc12d4e1c94d7595eeaf74be11ad47276c"
            },
            "downloads": -1,
            "filename": "pip_api-0.0.33-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6f22dfd0adf4857d53e9ed42cedbb5f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 120376,
            "upload_time": "2024-02-15T22:29:38",
            "upload_time_iso_8601": "2024-02-15T22:29:38.235395Z",
            "url": "https://files.pythonhosted.org/packages/d5/a5/ecff8712be393a0d9c221e036082163b69d491f99b7772d37b935cb078d6/pip_api-0.0.33-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae28da6bd24c67a6d52a535fa8b888b1495d1d2ec7b2705a45ce5d351a3047bb",
                "md5": "f1aff0e77ce752a7fc0f484a5752a432",
                "sha256": "1c2522ae21efcb034d89cc99f6cf1025293b31c63c29ee98b23f03a85f36bdae"
            },
            "downloads": -1,
            "filename": "pip-api-0.0.33.tar.gz",
            "has_sig": false,
            "md5_digest": "f1aff0e77ce752a7fc0f484a5752a432",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 123188,
            "upload_time": "2024-02-15T22:29:39",
            "upload_time_iso_8601": "2024-02-15T22:29:39.578817Z",
            "url": "https://files.pythonhosted.org/packages/ae/28/da6bd24c67a6d52a535fa8b888b1495d1d2ec7b2705a45ce5d351a3047bb/pip-api-0.0.33.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-15 22:29:39",
    "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"
}
        
Elapsed time: 0.23802s