pip-licenses
Dump the software license list of Python packages installed with pip.
Description
pip-licenses
Dump the software license list of Python packages installed with pip.
Table of Contents
- Description
- Installation
- Usage
- Command-Line Options
- Dockerfile
- About UnicodeEncodeError
- License
- Uninstallation
- Contributing
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
# 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
Execute the command with your venv (or virtualenv) environment.
# Install packages in your venv environment
(venv) $ pip install Django pip-licenses
# Check the licenses with your venv environment
(venv) $ pip-licenses
Name Version License
Django 2.0.2 BSD
pytz 2017.3 MIT
Command-Line Options
Common options
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.
(venv) $ pip-licenses --with-system | grep pip
pip 22.3.1 MIT License
pip-licenses 4.1.0 MIT License
(venv) $ pip-licenses --python=</path/to/other/env>/bin/python --with-system | grep pip
pip 23.0.1 MIT License
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.
(venv) $ pip show setuptools
Name: setuptools
Version: 38.5.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
The mixed mode (--from=mixed) of this tool works well and looks for licenses.
(venv) $ pip-licenses --from=mixed --with-system | grep setuptools
setuptools 38.5.0 MIT License
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.
(venv) $ pip-licenses --format=markdown
| Name | Version | License |
|--------|---------|---------|
| Django | 2.0.2 | BSD |
| pytz | 2017.3 | MIT |
When inserted in a markdown document, it is rendered as follows:
| Name | Version | License |
|---|---|---|
| Django | 2.0.2 | BSD |
| pytz | 2017.3 | MIT |
reST
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.
(venv) $ pip-licenses --format=rst
+--------+---------+---------+
| Name | Version | License |
+--------+---------+---------+
| Django | 2.0.2 | BSD |
+--------+---------+---------+
| pytz | 2017.3 | MIT |
+--------+---------+---------+
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.
(venv) $ pip-licenses --format=confluence
| Name | Version | License |
| Django | 2.0.2 | BSD |
| pytz | 2017.3 | MIT |
HTML
When executed with the --format=html option, you can output list in HTML table format. The h keyword is prepared as alias of html.
(venv) $ pip-licenses --format=html
<table>
<tr>
<th>Name</th>
<th>Version</th>
<th>License</th>
</tr>
<tr>
<td>Django</td>
<td>2.0.2</td>
<td>BSD</td>
</tr>
<tr>
<td>pytz</td>
<td>2017.3</td>
<td>MIT</td>
</tr>
</table>
JSON
When executed with the --format=json option, you can output list in JSON format easily allowing post-processing. The j keyword is prepared as alias of json.
[
{
"Author": "Django Software Foundation",
"License": "BSD",
"Name": "Django",
"URL": "https://www.djangoproject.com/",
"Version": "2.0.2"
},
{
"Author": "Stuart Bishop",
"License": "MIT",
"Name": "pytz",
"URL": "http://pythonhosted.org/pytz",
"Version": "2017.3"
}
]
JSON LicenseFinder
When executed with the --format=json-license-finder option, you can output list in JSON format that is identical to LicenseFinder. The jlf keyword is prepared as alias of jlf.
This makes pip-licenses a drop-in replacement for LicenseFinder.