pip-licenses
Dump the software license list of Python packages installed with pip.
Table of Contents
Description
pip-licenses is a CLI tool for checking the software license of installed Python packages with pip.
Implemented with the idea inspired by composer licenses command in Composer (a.k.a PHP package management tool).
https://getcomposer.org/doc/03-cli.md#licenses
Installation
Install it via PyPI using pip command.
# Install or Upgrade to newest available version
$ pip install -U pip-licenses
Legacy Python Hints
Note for Python 3.8 users: pip-licenses 5.x discontinued support for Python 3.8. If you want to use it with Python 3.8 anyway, install pip-licenses 4.5.x.
# Using old version for the Python 3.8 environment
$ pip install 'pip-licenses<5.0'
# If upgrading from pip-licenses 3.x, remove PTable
$ pip uninstall -y PTable
Note for Python 3.7 users: pip-licenses 4.x discontinued support earlier than the Python 3.7 EOL schedule. If you want to use it with Python 3.7, install pip-licenses 3.x.
# Using old version for the Python 3.7 environment
$ pip install 'pip-licenses<4.0'
Note: If you are still using Python 2.7, install version less than 2.0. No new features will be provided for version 1.x.
$ pip install 'pip-licenses<2.0'
Usage
Simply invoke the command to scan the current environment:
pip-licenses
demo$ pip-licenses
Name Version License
cffi 2.1.1 MIT-0
packaging 26.3 Apache-2.0 OR BSD-2-Clause
pycparser 3.0 BSD-3-Clause
Command-Line Options
Common options
| Option | Argument(s) | Default | Description |
|---|---|---|---|
--python |
path | current interpreter | Python executable whose sys.path is searched for packages. |
--from |
meta, classifier, mixed, all |
mixed |
Source used to look up license information. |
--order |
name, license, author, url, count |
name |
Column used to sort the output. |
--format |
plain, plain-vertical, markdown, rst, confluence, html, json, json-license-finder, csv |
plain |
Output format of the report. |
--summary |
None (flag takes no values) | off | Output a count summary per license instead of a package list. |
--output-file |
path | stdout | Write the result to the given file path. |
--ignore-packages |
package names | none | Exclude the listed packages from the output. |
--packages |
package names | all | Limit the output to the listed packages only. |
Option: python
By default, this tools finds the packages from the environment pip-licenses is launched from, by searching in current python's sys.path folders. In the case you want to search for packages in an other environment (e.g. if you want to run pip-licenses from its own isolated environment), you can specify a path to a python executable. The packages will be searched for in the given python's sys.path, free of pip-licenses dependencies.
demo$ pip-licenses --with-system | grep pip
pip 26.3 MIT
pip-licenses 6.0.0rc24 MIT
(venv) $ pip-licenses --python=</path/to/other/env>/bin/python --with-system | grep pip
pip 26.3 MIT
Option: from
By default, this tool finds the license from Trove Classifiers or package Metadata. Some Python packages declare their license only in Trove Classifiers.
(See also): Set license to MIT in setup.py by alisianoi ・ Pull Request #1058 ・ pypa/setuptools, PEP 314#License
For example, even if you check with the pip show command, the license is displayed as UNKNOWN or simply empty.
demo$ # this is what pip shows:
demo$ pip show aniso8601
Name: aniso8601
Version: 10.0.1
Summary: A library for parsing ISO 8601 strings.
Home-page: https://codeberg.org/nielsenb-jf/aniso8601
Author: Brandon Nielsen
Author-email: nielsenb@jetfuse.net
License:
Requires:
Required-by:
demo$ # this is what pip-licenses shows:
demo$ pip-licenses -p aniso8601 --from=mixed --with-system
Name Version License
aniso8601 10.0.1 BSD License
The mixed mode (--from=mixed) of this tool works well and looks for licenses.
In mixed mode, it first tries to look for licenses in the Trove Classifiers. When not found in the Trove Classifiers, the license declared in Metadata is displayed.
If you want to look only in metadata, use --from=meta. If you want to look only in Trove Classifiers, use --from=classifier.
To list license information from both metadata and classifier, use --from=all.
Note: If neither can find license information, please check with the with-authors and with-urls options and contact the software author.
- The
mkeyword is prepared as alias ofmeta. - The
ckeyword is prepared as alias ofclassifier. - The
mixkeyword is prepared as alias ofmixed.- Default behavior in this tool
Option: order
By default, it is ordered by package name.
If you give arguments to the --order option, you can output in other sorted order.
(venv) $ pip-licenses --order=license
Option: format
By default, it is output to the plain format.
Markdown
When executed with the --format=markdown option, you can output list in markdown format. The m md keyword is prepared as alias of markdown.
demo$ pip-licenses --format=markdown
| Name | Version | License |
|-------------------|---------|----------------------------|
| aniso8601 | 10.0.1 | BSD License |
| cffi | 2.1.1 | MIT-0 |
| dependency-groups | 1.3.2 | MIT |
| packaging | 26.3 | Apache-2.0 OR BSD-2-Clause |
| pycparser | 3.12 | BSD-3-Clause |
When inserted in a markdown document, it is rendered as follows:
| Name | Version | License |
|---|---|---|
| aniso8601 | 10.0.1 | BSD License |
| cffi | 2.1.1 | MIT-0 |
| dependency-groups | 1.3.2 | MIT |
| packaging | 26.3 | Apache-2.0 OR BSD-2-Clause |
| pycparser | 3.12 | BSD-3-Clause |
When executed with the --format=rst option, you can output list in "Grid tables" of reStructuredText format. The r rest keyword is prepared as alias of rst.
demo$ pip-licenses --format=rst
+-------------------+---------+----------------------------+
| Name | Version | License |
+-------------------+---------+----------------------------+
| aniso8601 | 10.0.1 | BSD License |
+-------------------+---------+----------------------------+
| cffi | 2.1.1 | MIT-0 |
+-------------------+---------+----------------------------+
| dependency-groups | 1.3.2 | MIT |
+-------------------+---------+----------------------------+
| packaging | 26.3 | Apache-2.0 OR BSD-2-Clause |
+-------------------+---------+----------------------------+
| pycparser | 3.12 | BSD-3-Clause |
+-------------------+---------+----------------------------+
Confluence
When executed with the --format=confluence option, you can output list in Confluence (or JIRA) Wiki markup format. The c keyword is prepared as alias of confluence.
demo$ pip-licenses --format=confluence
| Name | Version | License |
| aniso8601 | 10.0.1 | BSD License |
| cffi | 2.1.1 | MIT-0 |
| dependency-groups | 1.3.2 | MIT |
| packaging | 26.3 | Apache-2.0 OR BSD-2-Clause |
| pycparser | 3.12 | BSD-3-Clause |