pip-licenses

5.5.5 · active · verified Sat Apr 11

pip-licenses is a command-line interface (CLI) tool designed to efficiently list the software licenses of Python packages installed via pip. It is actively maintained with regular updates, aligning with the release cadence of `pip` itself. The current version is 5.5.5.

Warnings

Install

Quickstart

The primary usage of `pip-licenses` is through its command-line interface. After installation, simply running `pip-licenses` will display a table of all non-system Python packages and their associated licenses in your current environment. Common options include `--with-system` to include system packages, `--fail-on` to exit with an error if a specific license is detected, `--format` for different output types (e.g., json, html, markdown), and `--summary` to get a count of packages per license.

import os

# Install pip-licenses and a sample package (if not already installed)
# os.system('pip install Django pip-licenses')

# Basic usage: list all installed package licenses
print("\n--- Basic License List ---")
os.system('pip-licenses')

# Include system packages like pip and setuptools
print("\n--- With System Packages ---")
os.system('pip-licenses --with-system')

# Fail if a specific license (e.g., AGPL) is found
print("\n--- Fail on AGPL (example, might exit with error) ---")
# For demonstration, we use a common permissive license (MIT) to show failure.
# In a real scenario, you'd check for restrictive licenses like AGPL.
# This command will exit with a non-zero code if MIT is found.
# os.system('pip-licenses --fail-on "MIT License" --partial-match')

# Output in JSON format
print("\n--- Output in JSON Format (first 1000 chars) ---")
json_output = os.popen('pip-licenses --format=json').read()
print(json_output[:1000])

# Get a summary of licenses by count
print("\n--- License Summary ---")
os.system('pip-licenses --summary')

view raw JSON →