Skip to main content

Check python packages from requirement.txt and report issues

Project description

https://badge.fury.io/py/liccheck.svg https://github.com/dhatim/python-license-check/workflows/build/badge.svg https://codecov.io/gh/dhatim/python-license-check/branch/master/graph/badge.svg

Python License Checker

Check python packages listed in a requirements.txt file and report license issues.

About

You can define a list of authorized licenses, unauthorized licenses and authorized packages.

The tool will check the requirements.txt file, check packages and their dependencies and return an error if some packages are not compliant against the given strategy.

The tool has 3 levels of checks to select from:

Standard (default):

A package is considered as compliant when at least one of its licenses is in the authorized license list, or if the package is in the list of authorized packages.

Cautious:

Same as Standard, but a package is not considered compliant when one or more of its licenses is in the unauthorized license list, even if it also has a license in the authorized license list. A package is still compliant if present in the authorized packages list.

Paranoid:

All licenses listed for a package must be in the authorised license list for the package to be considered compliant. A package is still compliant if present in the authorized packages list.

Assumption

The tool requires to be installed in the same python (virtual) environment as the packages. This, because it uses pkg_resources to access the packages resources and thus, their licenses information.

How to install

$ pip install liccheck

How to use

liccheck will read the requirements.txt and verify compliance of packages against a strategy defined in the ini file. If the requirements file is not specified on the command line, it will search for requirements.txt in the current folder. You have to setup an ini file with an authorized license list, unauthorized license list and authorized package list. The packages from your requirements.txt need to all be installed in the same python environment/virtualenv as liccheck. If the ini file is not specified on the command line, it will search for liccheck.ini in the current folder.

Here is an example of a liccheck.ini file:

# Authorized and unauthorized licenses in LOWER CASE
[Licenses]
authorized_licenses:
        bsd
        new bsd
        bsd license
        new bsd license
        simplified bsd
        apache
        apache 2.0
        apache software license
        gnu lgpl
        lgpl with exceptions or zpl
        isc license
        isc license (iscl)
        mit
        mit license
        python software foundation license
        zpl 2.1

unauthorized_licenses:
        gpl v3

[Authorized Packages]
# Python software license (see http://zesty.ca/python/uuid.README.txt)
uuid: 1.30

Note: versions of authorized packages can be defined using PEP-0440 version specifiers, such as >=1.3,<1.4. The implementation uses the nice package semantic_version.

For demo purpose, let’s say your requirements.txt file contains this:

Flask>=0.12.1
flask_restful
jsonify
psycopg2>=2.7.1
nose
scipy
scikit-learn
pandas
numpy
argparse
uuid
sqlbuilder
proboscis
pyyaml>=3.12

The execution will output this:

$ liccheck -s my_strategy.ini -r my_project/required.txt
gathering licenses...23 packages and dependencies.
check forbidden packages based on licenses...none
check authorized packages based on licenses...19 packages.
check authorized packages...4 packages.
check unknown licenses...none

If some dependencies are unknown or are not matching the strategy, the output will be something like:

$ liccheck -s my_strategy.ini -r my_project/requirements.txt
    gathering licenses...32 packages and dependencies.
    check forbidden packages based on licenses...1 forbidden packages :
        Unidecode (0.4.21) : GPL ['GNU General Public License v2 or later (GPLv2+)']
          dependency:
              Unidecode << python-slugify << yoyo-migrations

    check authorized packages based on licenses...24 packages.
    check authorized packages...6 packages.
    check unknown licenses...1 unknown packages :
        feedparser (5.2.1) : UNKNOWN []
          dependency:
              feedparser

Also supports pyproject.toml like:

[project]
dependencies = [
    "Flask>=0.12.1",
    "flask_restful",
    "jsonify",
    "psycopg2>=2.7.1",
    "nose",
    "scipy",
    "scikit-learn",
    "pandas",
    "numpy",
    "argparse",
    "uuid",
    "sqlbuilder",
    "proboscis",
        "pyyaml>=3.12",
]

[project.optional-dependencies]
test = [
    "pytest>=3.6.3",
]

[tool.liccheck]
authorized_licenses = [
    "bsd",
            "new bsd",
            "bsd license",
            "new bsd license",
            "simplified bsd",
            "apache",
            "apache 2.0",
            "apache software license",
            "gnu lgpl",
            "lgpl with exceptions or zpl",
            "isc license",
            "isc license (iscl)",
            "mit",
            "mit license",
            "python software foundation license",
            "zpl 2.1",
]
unauthorized_licenses = [
    "gpl v3",
]
# strategy_ini_file = "./liccheck.ini"
# level = "STANDARD"
# requirement_txt_file = "./requirements.txt" # ignored if dependencies or optional_dependencies are defined
# reporting_txt_file = "path/to/reporting.txt file" # by default is None
# no_deps = false
dependencies = true # to load [project.dependencies]
optional_dependencies = ["test"] # to load extras from [project.optional-dependencies]

[tool.liccheck.authorized_packages]
uuid = 1.30

Using liccheck with pre-commit

Add this to your .pre-commit-config.yaml:

- repo: https://github.com/dhatim/python-license-check
  rev: master
  hooks:
  - id: liccheck
    language: system

Contributing

To run the tests:

$ tox -p all

Licensing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liccheck-0.7.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liccheck-0.7.0-py2.py3-none-any.whl (13.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file liccheck-0.7.0.tar.gz.

File metadata

  • Download URL: liccheck-0.7.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for liccheck-0.7.0.tar.gz
Algorithm Hash digest
SHA256 41ac5c945663f2967d15158d8d85d6a051c3472ea796615b63a16cd80b17c7d7
MD5 1652dfaa65aac5c16c926236a565b39f
BLAKE2b-256 568a0745494e85da11581bd4ba17792a91b33da6bd76b0aeb94f21d7768acc70

See more details on using hashes here.

File details

Details for the file liccheck-0.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: liccheck-0.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for liccheck-0.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 88c848a24831346710b377893044fbfc691d5b08a47251c6b9e01ec552decb54
MD5 34973791ee5eea16f41aff3958b888ae
BLAKE2b-256 d515f7a5c8fc0c3c71ba4b2e48ed342c5373f5be46d8e26730da5c9bf3187375

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page