Get Licenses of Python Packages using pip-licenses

Get Licenses of Python Packages using pip-licenses

Managing open-source dependencies also involves understanding their licensing terms. Each package included in a Python project may come with specific conditions that affect distribution, modification, or commercial use. Keeping an overview of these licenses helps ensure proper compliance and reduces potential legal risks. The pip-licenses tool offers a simple way to generate this information directly from the current Python setup. This tutorial explains how to get licenses of Python packages using pip-licenses.

Before starting, install the pip-licenses using pip:

pip install pip-licenses

Once installed, run the following command to retrieve license details for all installed packages:

pip-licenses

This command scans the current environment and produces a table containing package names, versions, and their respective licenses. A typical output may look like this:

Name    Version  License
numpy   2.2.6    BSD License
pillow  12.1.1   MIT-CMU

By default, specific system-level packages (such as pip, setuptools, wheel, and internal dependencies used by the pip-licenses) are excluded from the results. To include these in the report, use the --with-system option:

pip-licenses --with-system

Output example:

Name          Version  License
numpy         2.2.6    BSD License
pillow        12.1.1   MIT-CMU
pip           23.2.1   MIT License
pip-licenses  5.5.1    MIT
prettytable   3.17.0   BSD-3-Clause
setuptools    68.2.0   MIT License
tomli         2.4.0    MIT
wcwidth       0.6.0    MIT
wheel         0.41.2   MIT License

Leave a Comment

Cancel reply

Your email address will not be published.