Skip to main content

pylic - Python license checker GitHub license PyPI version

A Python license checker. pylic is PEP-639-compliant and supports the SPDX License Expression syntax.

Principles:

  • All licenses of all installed packages are relevant.
  • All installed packages without a license are considered unsafe and have to be listed as such.
  • Every license has to be allowed explicitly.

Installation

pip install pylic

Configuration

pylic needs be run in the directory where your pyproject.toml file is located. You can configure

  • safe_licenses: All licenses you consider safe for usage. The string comparison is case-insensitive.
  • unsafe_packages: List packages that have no license or use licenses not considered safe.
[tool.pylic]
safe_licenses = [
    "Apache Software License",
    "Apache License 2.0",
    "MIT License",
    "Python Software Foundation License",
    "Mozilla Public License 2.0 (MPL 2.0)",
]
unsafe_packages = [
    "unsafe_package",
]

Commands

pylic provides the following commands (also see pylic --help):

  • check: Checks all installed licenses.
  • list: Lists all installed packages and their corresponding license.

Usage Example

Create a venv to start with a clean ground and activate it

python -m venv .venv
source .venv/bin/activate

Install pylic and create an empty pyproject.toml

pip install pylic
touch pyproject.toml

Install all your dependencies

pip install <packageA> <packageB>

Run pylic

pylic check

The output will be similar to

Found unsafe packages:
  pkg_resources (0.0.0)
Found unsafe licenses:
  pip (18.1): MIT License
  zipp (3.4.1): MIT License
  toml (0.10.2): MIT License
  pylic (1.2.0): MIT License
  setuptools (40.8.0): MIT License
  typing-extensions (3.7.4.3): Python Software Foundation License
  importlib-metadata (3.9.0): Apache Software License

The return code of pylic is in this case non-zero due to unsafe licenses. This allows usage of pylic in CI.

echo $? # prints 1

As these licenses and packages are all ok we can configure pylic accordingly

cat <<EOT >> pyproject.toml
[tool.pylic]
safe_licenses = ["Apache Software License", "MIT License", "Python Software Foundation License"]
unlicensed_packages = ["pkg_resources"]
EOT

After rerunning pylic check the output now reveals a successful validation

✨ All licenses ok ✨

Also the return code now signals that all is good

echo $? # prints 0

Use pylic list to list all installed packages and their corresponding licenses.

Advanced Usage

In cases where the safe licenses or unsafe packages are centrally managed keeping the configuration in perfect sync to the installed packages might be too cumbersome or even impossible. To support these use cases the check command provides the two options (see also check --help) --allow-extra-safe-licenses and --allow-extra-unsafe-packages. These options only affect the returned status code and will keep all corresponding warnings unchanged.

Pre-commit

pylic provides a pre-commit integration. Follow the instructions and enable automatic license checking on commits by adding

-  repo: https://github.com/ubersan/pylic
   rev: v<version>
   hooks:
   -  id: pylic

to your .pre-commit-config.yaml file.

Development

Required tools:

Run uv sync to install all necessary dependencies. Checkout the [tool.taskipy.tasks] (see taskipy) section in the pyproject.toml file for utility tasks. You can run these with uv run task <task>.

Creating a new release is as simple as:

  • Update version in the pyproject.toml and the __version__.py file.
  • Run git tag <new-version>.
  • Run git push origin <new-version>.

Release files for pylic 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylic 5.0.1
File Size Uploaded
pylic-5.0.1.tar.gz 22.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylic 5.0.1
File Interpreter ABI Platform
pylic-5.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / pylic-5.0.1.tar.gz

Download URL pylic-5.0.1.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2948a64298f3f3b3a1ce8b81e0bfc6ee73eeccb5a9a8785c3c5c362d771d7f6a
BLAKE2b-256 checksum
How to use checksums
8080f9c03d4c6f8e6db67582408dbb4c042dd788435d95e75268af61a27729d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.8

Release files / pylic-5.0.1-py3-none-any.whl

Download URL pylic-5.0.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae9a863acec4df949f005c3f30c78045a204ee19a7e4c652fdf791d72b4b8bad
BLAKE2b-256 checksum
How to use checksums
6cbfdbb14e8e2d72952784570156fa885750eaf81fd03e45c93bf5dc2c1ab97b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.8

Release history Release notifications | RSS feed

This release

5.0.1 This release

2 release files

5.0.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.6.1

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.5

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page