### License Check Configuration Example (pyproject.toml) Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md An example of how to configure the licensecheck tool within a pyproject.toml file. ```APIDOC ## License Check Configuration Example ### Description Configuration files are parsed in the following order: `pyproject.toml`, `setup.cfg`, `licensecheck.toml`, `licensecheck.json`, `~/licensecheck.toml`, `~/licensecheck.json`. All config files are parsed, however configuration defined in previous files takes precedent. ### Method Configuration File ### Endpoint N/A ### Parameters #### TOML Configuration (`[tool.licensecheck]` section) - **license** (string) - Specify the project license explicitly - **format** (string) - Output format (e.g., "json", "csv", etc.) - **requirements_paths** (list of strings) - List of filenames to read from - **groups** (list of strings) - List of selected groups - **extras** (list of strings) - List of selected extras - **file** (string) - Output file (leave empty for stdout) - **ignore_packages** (list of strings) - Packages/dependencies to ignore - **fail_packages** (list of strings) - Packages/dependencies that cause failure - **ignore_licenses** (list of strings) - Licenses to ignore - **fail_licenses** (list of strings) - Licenses that cause failure - **only_licenses** (list of strings) - Allowed licenses (all others will fail) - **skip_dependencies** (list of strings) - Dependencies to skip (compatibility = True) - **hide_output_parameters** (list of strings) - Parameters to hide from output - **show_only_failing** (boolean) - Show only incompatible/failing packages - **pypi_api** (string) - Custom PyPI API endpoint - **zero** (boolean) - Return non-zero exit code for incompatible licenses (for CI/CD) ### Request Example ```toml [tool.licensecheck] license = "mit" format = "simple" requirements_paths = [] groups = [] extras = [] file = "" ignore_packages = [] fail_packages = [] ignore_licenses = [] fail_licenses = [] only_licenses = [] skip_dependencies = [] hide_output_parameters = [] show_only_failing = false pypi_api = "https://pypi.org" zero = false ``` ### Response N/A ``` -------------------------------- ### Get project metadata Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Extracts metadata from setup.cfg or pyproject.toml files. ```python @staticmethod def get_metadata() -> dict[str, Any]: ... ``` -------------------------------- ### Legacy setup.cfg License Configuration Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/README.md Example of how to specify license information in a legacy setup.cfg file. This is useful for older Python projects. ```ini [metadata] classifiers = License :: OSI Approved :: MIT License Programming Language :: Python :: 3.8 license = MIT ``` -------------------------------- ### LocalPackageInfo Class Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Handles retrieval of package information from local installations. ```APIDOC ## LocalPackageInfo Class Handles retrieval of package info from local installation. ### Signature ```python class LocalPackageInfo: def __init__(self, package: PackageInfo) -> None: ... ``` ### Methods #### LocalPackageInfo().get_author [Show source in packageinfo.py:153](../../../licensecheck/packageinfo.py#L153) #### Signature ```python def get_author(self) -> str | None: ... ``` #### LocalPackageInfo().get_homePage [Show source in packageinfo.py:150](../../../licensecheck/packageinfo.py#L150) #### Signature ```python def get_homePage(self) -> str | None: ... ``` #### LocalPackageInfo().get_license [Show source in packageinfo.py:137](../../../licensecheck/packageinfo.py#L137) #### Signature ```python def get_license(self) -> str | None: ... ``` #### LocalPackageInfo().get_name [Show source in packageinfo.py:144](../../../licensecheck/packageinfo.py#L144) #### Signature ```python def get_name(self) -> str | None: ... ``` #### LocalPackageInfo().get_size [Show source in packageinfo.py:156](../../../licensecheck/packageinfo.py#L156) Retrieve installed package size. #### Arguments - `package` *ucstr* - Package name. #### Returns Type: *int* Size in bytes. #### Signature ```python def get_size(self) -> int: ... ``` #### LocalPackageInfo().get_version [Show source in packageinfo.py:147](../../../licensecheck/packageinfo.py#L147) #### Signature ```python def get_version(self) -> str | None: ... ``` ``` -------------------------------- ### Install Python on Linux Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Installs Python using system package managers on Linux distributions. ```bash sudo apt install python3.x ``` ```bash sudo dnf install python3.x ``` -------------------------------- ### Install Python on MacOS via Homebrew Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Uses Homebrew to install Python on macOS. ```bash brew install python@3.x ``` -------------------------------- ### JSON Configuration for LicenseCheck Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Configure LicenseCheck using a `licensecheck.json` file. This example shows settings for license type, output format, allowed licenses, and packages to ignore. ```json // licensecheck.json configuration { "tool": { "licensecheck": { "license": "mit", "format": "json", "only_licenses": ["mit", "apache", "bsd"], "ignore_packages": ["internal-*"], "zero": true } } } ``` -------------------------------- ### Get project license Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Extracts the license string from project metadata. ```python @staticmethod def get_license() -> ucstr: ... ``` -------------------------------- ### Install licensecheck via PIP Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Installs the licensecheck package using the Python package manager. ```python pip install licensecheck ``` -------------------------------- ### Poetry Project Configuration Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/README.md Example of a pyproject.toml file configured for a Poetry project. Includes package metadata, license, and dependencies. ```toml [tool.poetry] name = "mypackage" version = "0.1.0" description = "A simple Python package" license = "MIT" authors = ["Author "] classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.8" ] [tool.poetry.dependencies] python = "^3.8" ``` -------------------------------- ### Install Python on Windows via Chocolatey Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Uses the Chocolatey package manager to install Python on Windows systems. ```powershell choco install python ``` -------------------------------- ### Flit Project Configuration Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/README.md Example of a pyproject.toml file configured for a Flit project. Specifies module, description, license, and classifiers. ```toml [tool.flit.metadata] module = "mypackage" description = "A simple Python package" license = "MIT" classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.8" ] ``` -------------------------------- ### Retrieve LocalPackageInfo attributes Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Methods for accessing specific metadata fields from a locally installed package. ```python def get_author(self) -> str | None: ... ``` ```python def get_homePage(self) -> str | None: ... ``` ```python def get_license(self) -> str | None: ... ``` ```python def get_name(self) -> str | None: ... ``` ```python def get_size(self) -> int: ... ``` ```python def get_version(self) -> str | None: ... ``` -------------------------------- ### do_get_reqs Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/resolvers/native.md Retrieves requirements using specified methods and options. This is the underlying machinery for getting requirements. ```APIDOC ## do_get_reqs ### Description Underlying machineary to get requirements. ### Method GET (or relevant method based on usage context, not explicitly defined) ### Endpoint /fhpythonutils/licensecheck/resolvers/native ### Parameters #### Query Parameters - **using** (str) - Required - Specifies the requirements manager to use (e.g., 'requirements', 'poetry', or 'PEP631'). - **skipDependencies** (list[str]) - Optional - A list of dependencies to skip during requirement retrieval. - **extras** (list[str]) - Optional - Specifies extra features or dependencies to include. - **pyproject** (dict[str, Any]) - Optional - Configuration details from a pyproject.toml file. - **requirementsPaths** (list[Path]) - Optional - Paths to requirement files. ### Response #### Success Response (200) - **requirements** (set[str]) - A set containing the names of the requirement packages. ``` -------------------------------- ### get_reqs Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/resolvers/native.md A public interface to get requirements, abstracting the underlying retrieval logic. ```APIDOC ## get_reqs ### Description Retrieves a set of requirement packages. ### Method GET (or relevant method based on usage context, not explicitly defined) ### Endpoint /fhpythonutils/licensecheck/resolvers/native ### Parameters #### Query Parameters - **skipDependencies** (list[str]) - Optional - A list of dependencies to skip. - **extras** (list[str]) - Optional - Specifies extra features or dependencies to include. - **requirementsPaths** (list[Path]) - Optional - Paths to requirement files. - **pyproject** (dict[str, Any]) - Optional - Configuration details from a pyproject.toml file. ### Response #### Success Response (200) - **requirements** (set[str]) - A set containing the names of the requirement packages. ``` -------------------------------- ### Get License Types from String Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/license_matrix/index.md Retrieves a list of License objects from a given license string. It can also skip specified licenses during the process. ```python def licenseType(lice: ucstr, ignoreLicenses: list[ucstr] | None = None) -> list[L]: ... ``` -------------------------------- ### Get Filtered Package Dictionary Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/types.md Returns a dictionary of package information, excluding specified parameters. Useful for controlling output. ```python def get_filtered_dict(self, hide_output_parameters: list[ucstr]) -> dict: ... ``` -------------------------------- ### License Handling and Compatibility Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Demonstrates how to handle multiple licenses, perform single license lookups, and check for license compatibility between a project and its dependencies. ```APIDOC ## License Handling and Compatibility ### Description Functions for parsing licenses, looking up license enums, and checking compatibility. ### Methods - `licenseType(licenses_string)`: Parses a string of licenses separated by ';;' into a list of License enums. - `licenseLookup(license_string)`: Looks up a single license string and returns the corresponding License enum. - `depCompatWMyLice(myLicense, depLice, ignoreLicenses, failLicenses, onlyLicenses)`: Checks if dependency licenses are compatible with the project's license, with options to ignore, fail, or only allow specific licenses. ### Parameters - **licenseType**: `licenses_string` (str) - A string containing one or more licenses separated by ';;'. - **licenseLookup**: `license_string` (str) - The license string to look up. - **depCompatWMyLice**: - `myLicense` (License enum) - The license of the current project. - `depLice` (list of License enums) - A list of licenses for the dependency. - `ignoreLicenses` (list of License enums) - Licenses to ignore during compatibility check. - `failLicenses` (list of License enums) - Licenses that will always result in incompatibility. - `onlyLicenses` (list of License enums) - If not empty, only these licenses are considered compatible. ### Available License Enum Values `License.PUBLIC`, `License.UNLICENSE`, `License.MIT`, `License.BOOST`, `License.BSD`, `License.ISC`, `License.NCSA`, `License.PSFL`, `License.APACHE`, `License.ECLIPSE`, `License.ACADEMIC_FREE`, `License.LGPL_2`, `License.LGPL_3`, `License.GPL_2`, `License.GPL_3`, `License.AGPL_3_PLUS`, `License.MPL`, `License.EU`, `License.PROPRIETARY`, `License.UNKNOWN`, `License.NO_LICENSE` ### Example Usage ```python from licensecheck.types import License, ucstr # Handle multiple licenses licenses = licenseType(ucstr("APACHE SOFTWARE LICENSE;; MIT LICENSE")) print(licenses) # [, ] # Single license lookup license_enum = licenseLookup(ucstr("BSD-3-CLAUSE")) print(license_enum) # License.BSD # Check compatibility is_compatible = depCompatWMyLice( myLicense=License.MIT, # Your project license depLice=[License.BSD, License.APACHE], # Dependency licenses ignoreLicenses=[], # Licenses to ignore failLicenses=[License.GPL_3], # Licenses to always fail onlyLicenses=[], # Allowed licenses (empty = all) ) print(f"Compatible: {is_compatible}") # Compatible: True ``` ``` -------------------------------- ### Run licensecheck with default configuration Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/README.md Executes licensecheck using the pyproject.toml file as the default source for dependencies. ```txt >> licensecheck ... List Of Packages ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Compatible ┃ Package ┃ License(s) ┃ ┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ ✔ │ appdirs │ MIT LICENSE │ │ ✔ │ attrs │ MIT LICENSE │ │ ✔ │ boolean-py │ BSD-2-CLAUSE │ │ ✔ │ cattrs │ MIT LICENSE │ │ ✔ │ certifi │ MOZILLA PUBLIC LICENSE 2.0 _MPL 2.0_ │ │ ✔ │ charset-normalizer │ MIT LICENSE │ │ ✔ │ colorama │ BSD LICENSE │ │ ✔ │ fhconfparser │ MIT LICENSE │ │ ✔ │ idna │ BSD LICENSE │ │ ✔ │ license-expression │ APACHE-2.0 │ │ ✔ │ loguru │ MIT LICENSE │ │ ✔ │ markdown │ BSD LICENSE │ │ ✔ │ markdown-it-py │ MIT LICENSE │ │ ✔ │ mdurl │ MIT LICENSE │ │ ✔ │ packaging │ APACHE SOFTWARE LICENSE;; BSD LICENSE │ │ ✔ │ platformdirs │ MIT LICENSE │ │ ✔ │ pygments │ BSD LICENSE │ │ ✔ │ requests │ APACHE SOFTWARE LICENSE │ │ ✔ │ requests-cache │ BSD LICENSE │ │ ✔ │ requirements-parser │ APACHE SOFTWARE LICENSE │ │ ✔ │ rich │ MIT LICENSE │ │ ✔ │ setuptools │ MIT LICENSE │ │ ✔ │ six │ MIT LICENSE │ │ ✔ │ tomli │ MIT LICENSE │ │ ✔ │ types-setuptools │ APACHE SOFTWARE LICENSE │ │ ✔ │ url-normalize │ MIT LICENSE │ │ ✔ │ urllib3 │ MIT LICENSE │ │ ✔ │ uv │ APACHE SOFTWARE LICENSE;; MIT LICENSE │ │ ✔ │ win32-setctime │ MIT LICENSE │ └────────────┴─────────────────────┴───────────────────────────────────────┘ ``` -------------------------------- ### Run licensecheck with pyproject.toml Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/examples.md Execute licensecheck directly in a directory to use pyproject.toml as the default configuration. ```txt >> licensecheck ... ``` -------------------------------- ### CLI Entry Point Function Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/cli.md This is the main entry point for the CLI. It does not take any arguments and returns nothing. ```python def cli() -> None: ... ``` -------------------------------- ### Automate project building Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Commands to generate documentation, export requirements, and build library artifacts. ```sh handsdown --cleanup -o documentation/reference poetry export -f requirements.txt --output requirements.txt poetry export -f requirements.txt --with dev --output requirements_optional.txt poetry build ``` -------------------------------- ### Pipe requirements.txt to licensecheck Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/examples.md Use this command to analyze dependencies listed in a requirements.txt file. ```txt >> cat ./requirements.txt | licensecheck Info ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ ┃ Item ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩ │ program │ licensecheck │ │ version │ 2025 │ │ license │ MIT LICENSE │ │ project_license │ MIT LICENSE │ └─────────────────┴──────────────┘ List Of Packages ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Compatible ┃ Package ┃ License(s) ┃ ┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ ✔ │ appdirs │ MIT LICENSE │ │ ✔ │ attrs │ MIT LICENSE │ │ ✔ │ boolean-py │ BSD-2-CLAUSE │ │ ✔ │ cattrs │ MIT LICENSE │ │ ✔ │ certifi │ MOZILLA PUBLIC LICENSE 2.0 _MPL 2.0_ │ │ ✔ │ charset-normalizer │ MIT LICENSE │ │ ✔ │ colorama │ BSD LICENSE │ │ ✔ │ fhconfparser │ MIT LICENSE │ │ ✔ │ idna │ BSD LICENSE │ │ ✔ │ license-expression │ APACHE-2.0 │ │ ✔ │ loguru │ MIT LICENSE │ │ ✔ │ markdown │ BSD LICENSE │ │ ✔ │ markdown-it-py │ MIT LICENSE │ │ ✔ │ mdurl │ MIT LICENSE │ │ ✔ │ packaging │ APACHE SOFTWARE LICENSE;; BSD LICENSE │ │ ✔ │ platformdirs │ MIT LICENSE │ │ ✔ │ pygments │ BSD LICENSE │ │ ✔ │ requests │ APACHE SOFTWARE LICENSE │ │ ✔ │ requests-cache │ BSD LICENSE │ │ ✔ │ requirements-parser │ APACHE SOFTWARE LICENSE │ │ ✔ │ rich │ MIT LICENSE │ │ ✔ │ setuptools │ MIT LICENSE │ │ ✔ │ six │ MIT LICENSE │ │ ✔ │ tomli │ MIT LICENSE │ │ ✔ │ types-setuptools │ APACHE SOFTWARE LICENSE │ │ ✔ │ url-normalize │ MIT LICENSE │ │ ✔ │ urllib3 │ MIT LICENSE │ │ ✔ │ uv │ APACHE SOFTWARE LICENSE;; MIT LICENSE │ │ ✔ │ win32-setctime │ MIT LICENSE │ └────────────┴─────────────────────┴───────────────────────────────────────┘ ``` -------------------------------- ### Basic LicenseCheck Usage Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Run LicenseCheck to analyze dependencies from pyproject.toml or pipe requirements.txt. Specify the project license explicitly if needed. ```bash licensecheck ``` ```bash cat requirements.txt | licensecheck ``` ```bash licensecheck --license mit ``` -------------------------------- ### Initialize PackageInfo Post-Initialization Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/types.md This method is automatically called after a PackageInfo object is created to set the name and version. ```python def __post_init__(self) -> None: ... ``` -------------------------------- ### Python API: PackageInfoManager Initialization Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Initialize `PackageInfoManager` to handle dependency resolution and package information retrieval. Use the default PyPI or specify a custom PyPI server URL. ```python from licensecheck.packageinfo import PackageInfoManager from licensecheck.types import ucstr # Initialize with default PyPI manager = PackageInfoManager() # Or use a custom PyPI server manager = PackageInfoManager(base_pypi_url="https://my-pypi.example.com") ``` -------------------------------- ### ProjectMetadata API Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Handles extraction of project metadata from configuration files like setup.cfg or pyproject.toml. ```APIDOC ## ProjectMetadata Handles extraction of project metadata from configuration files. ### ProjectMetadata.get_license Extract license from project metadata. #### Returns Type: *ucstr* License string. #### Signature ```python @staticmethod def get_license() -> ucstr: ... ``` ### ProjectMetadata.get_metadata Extract project metadata from setup.cfg or pyproject.toml. #### Returns Type: *dict[str, Any]* Extracted metadata. #### Signature ```python @staticmethod def get_metadata() -> dict[str, Any]: ... ``` ``` -------------------------------- ### Python API: PackageInfoManager Resolve Requirements and Get Packages Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Use `PackageInfoManager` to resolve project requirements from various sources like `pyproject.toml` or `requirements.txt`, including dependency groups and optional extras. Then, retrieve detailed information for each resolved package. ```python # Resolve requirements from various sources manager.resolve_requirements( requirements_paths=["pyproject.toml"], # Can include requirements.txt groups=["dev", "test"], # Dependency groups extras=["all"], # Optional extras skip_dependencies=[ucstr("VENDORED")], # Skip specific deps ) # Get package information packages = manager.getPackages() for pkg in packages: print(f"Package: {pkg.name}") print(f" Version: {pkg.version}") print(f" License: {pkg.license}") print(f" Author: {pkg.author}") print(f" Homepage: {pkg.homePage}") print(f" Size: {pkg.size} bytes") # Output: # Package: requests # Version: 2.31.0 # License: APACHE SOFTWARE LICENSE # Author: Kenneth Reitz # Homepage: https://requests.readthedocs.io # Size: 123456 bytes ``` -------------------------------- ### LicenseCheck Output and Grouping Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Control the output format (json, markdown, html, csv, ansi, simple) and specify output files. Include specific dependency groups like 'dev' or 'test', and extras. ```bash licensecheck --format json ``` ```bash licensecheck --format html --file licenses.html ``` ```bash licensecheck --groups dev test ``` ```bash licensecheck --extras all ``` ```bash licensecheck --pypi-api https://my-pypi-server.com ``` -------------------------------- ### Manage Package Metadata with Types Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Use the PackageInfo class to store package details and the ucstr utility for case-insensitive license string comparisons. ```python from licensecheck.types import PackageInfo, License, ucstr, UNKNOWN, JOINS # Create a PackageInfo object pkg = PackageInfo( name="mypackage", version="1.0.0", size=12345, homePage="https://github.com/user/mypackage", author="John Doe", license=ucstr("MIT LICENSE"), licenseCompat=True, errorCode=0, ) # Access computed property print(pkg.namever) # "mypackage-1.0.0" # Get filtered dictionary (for hiding certain fields in output) filtered = pkg.get_filtered_dict(hide_output_parameters=[ucstr("SIZE"), ucstr("AUTHOR")]) print(filtered) # Use ucstr for case-insensitive license comparison license_str = ucstr("mit license") print(license_str) # "MIT LICENSE" ``` -------------------------------- ### Licensecheck CLI Usage Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Use this command to check project dependencies' licenses against a specified project license. Options allow customization of output format, input files, package/license filtering, and CI/CD integration. ```txt usage: licensecheck [-h] [--license LICENSE] [--format FORMAT] [--requirements-paths REQUIREMENTS_PATHS [REQUIREMENTS_PATHS ...]] [--groups GROUPS [GROUPS ...]] [--extras EXTRAS [EXTRAS ...]] [--file FILE] [--ignore-packages IGNORE_PACKAGES [IGNORE_PACKAGES ...]] [--fail-packages FAIL_PACKAGES [FAIL_PACKAGES ...]] [--ignore-licenses IGNORE_LICENSES [IGNORE_LICENSES ...]] [--fail-licenses FAIL_LICENSES [FAIL_LICENSES ...]] [--only-licenses ONLY_LICENSES [ONLY_LICENSES ...]] [--skip-dependencies SKIP_DEPENDENCIES [SKIP_DEPENDENCIES ...]] [--hide-output-parameters HIDE_OUTPUT_PARAMETERS [HIDE_OUTPUT_PARAMETERS ...]] [--show-only-failing] [--pypi-api PYPI_API] [--zero] Output the licenses used by dependencies and check if these are compatible with the project license. options: -h, --help show this help message and exit --license LICENSE, -l LICENSE Specify the project license explicitly, rather than rely on licensecheck interpreting this from pyproject.toml --format FORMAT, -f FORMAT Output format. one of: json, markdown, html, csv, ansi, simple. default=simple --requirements-paths REQUIREMENTS_PATHS [REQUIREMENTS_PATHS ...], -r REQUIREMENTS_PATHS [REQUIREMENTS_PATHS ...] Filenames to read from (omit for stdin if piping, else pyproject.toml) --groups GROUPS [GROUPS ...], -g GROUPS [GROUPS ...] Select groups from supported files --extras EXTRAS [EXTRAS ...], -e EXTRAS [EXTRAS ...] Select extras from supported files --file FILE, -o FILE Filename to write output to (omit this for stdout) --ignore-packages IGNORE_PACKAGES [IGNORE_PACKAGES ...] List of packages/dependencies to ignore (compat=True), globs are supported --fail-packages FAIL_PACKAGES [FAIL_PACKAGES ...] List of packages/dependencies to fail (compat=False), globs are supported --ignore-licenses IGNORE_LICENSES [IGNORE_LICENSES ...] List of licenses to ignore (skipped, compat may still be False) --fail-licenses FAIL_LICENSES [FAIL_LICENSES ...] List of licenses to fail (compat=False) --only-licenses ONLY_LICENSES [ONLY_LICENSES ...] List of allowed licenses (packages/dependencies with any other license will fail) --skip-dependencies SKIP_DEPENDENCIES [SKIP_DEPENDENCIES ...] List of packages/dependencies to skip (this sets the 'compatability' to True) --hide-output-parameters HIDE_OUTPUT_PARAMETERS [HIDE_OUTPUT_PARAMETERS ...] List of parameters to hide from the produced output --show-only-failing Only output a list of incompatible/ failing packages from this lib --pypi-api PYPI_API Specify a custom pypi api endpoint, for example if using a custom pypi server --zero, -0 Return non zero exit code if an incompatible license is found, ideal for CI/CD ``` -------------------------------- ### Test Entry Point Function Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/cli.md This function serves as a test entry point for the CLI. It accepts a dictionary of arguments and returns an integer. It utilizes FHConfParser for configuration, which checks files in a specific order. ```python def main(args: dict) -> int: ... ``` -------------------------------- ### Perform License Lookups and Compatibility Checks Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Use licenseType and licenseLookup to parse license strings into enums. Use depCompatWMyLice to verify if dependency licenses are compatible with your project's license. ```python # Handle multiple licenses (separated by ;;) licenses = licenseType(ucstr("APACHE SOFTWARE LICENSE;; MIT LICENSE")) print(licenses) # [, ] # Single license lookup license_enum = licenseLookup(ucstr("BSD-3-CLAUSE")) print(license_enum) # License.BSD # Check if dependency license is compatible with project license is_compatible = depCompatWMyLice( myLicense=License.MIT, # Your project license depLice=[License.BSD, License.APACHE], # Dependency licenses ignoreLicenses=[], # Licenses to ignore failLicenses=[License.GPL_3], # Licenses to always fail onlyLicenses=[], # Allowed licenses (empty = all) ) print(f"Compatible: {is_compatible}") # Compatible: True ``` -------------------------------- ### Run tests Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Commands to execute the test suite using poetry or tox. ```sh poetry run pytest ``` ```sh tox ``` -------------------------------- ### LicenseCheck Output Formats Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Utilize various output formats for different needs: CSV for spreadsheets, JSON for programmatic use, Markdown for documentation, and HTML for web reports. Parameters like size, author, and homePage can be hidden. ```bash # CSV format - ideal for spreadsheets licensecheck --format csv ``` ```json { "info": {"program": "licensecheck", "version": "2025", "license": "MIT LICENSE"}, "project_license": "MIT LICENSE", "packages": [ {"name": "requests", "version": "2.31.0", "license": "APACHE SOFTWARE LICENSE", ...} ] } ``` ```bash # Markdown format - ideal for documentation licensecheck --format markdown --file LICENSES.md ``` ```bash # HTML format - ideal for web reports licensecheck --format html --file licenses.html ``` ```bash # Hide specific output parameters licensecheck --hide-output-parameters size author homePage ``` -------------------------------- ### Licensecheck CLI Entry Point Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/cli.md The main entry point for the licensecheck CLI application. ```APIDOC ## cli cli ### Description Cli entry point. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters None ### Request Example None ### Response #### Success Response (None) None #### Response Example None ``` -------------------------------- ### Clone the repository Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Uses git to clone the project source code from GitHub. ```bash git clone https://github.com/FHPythonUtils/LicenseCheck ``` -------------------------------- ### Licensecheck CLI Test Entry Point Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/cli.md A test entry point for the licensecheck CLI, which handles configuration parsing. ```APIDOC ## main main ### Description Test entry point. Parses configuration using FHConfParser. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **args** (dict) - Required - Arguments for the main function. ### Request Example ```json { "args": {} } ``` ### Response #### Success Response (int) - **return_value** (int) - The exit code of the test entry point. #### Response Example ```json { "return_value": 0 } ``` ``` -------------------------------- ### Define LocalPackageInfo class Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Initializes the LocalPackageInfo class for handling local package metadata retrieval. ```python class LocalPackageInfo: def __init__(self, package: PackageInfo) -> None: ... ``` -------------------------------- ### Licensecheck TOML Configuration Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Configure licensecheck behavior using a TOML file, such as pyproject.toml. Settings defined in earlier files take precedence over later ones. ```toml [tool.licensecheck] license = "mit" # Specify the project license explicitly format = "simple" # Output format (e.g., "json", "csv", etc.) requirements_paths = [] # List of filenames to read from groups = [] # List of selected groups extras = [] # List of selected extras file = "" # Output file (leave empty for stdout) ignore_packages = [] # Packages/dependencies to ignore fail_packages = [] # Packages/dependencies that cause failure ignore_licenses = [] # Licenses to ignore fail_licenses = [] # Licenses that cause failure only_licenses = [] # Allowed licenses (all others will fail) skip_dependencies = [] # Dependencies to skip (compatibility = True) hide_output_parameters = [] # Parameters to hide from output show_only_failing = false # Show only incompatible/failing packages pypi_api = "https://pypi.org" # Custom PyPI API endpoint zero = false # Return non-zero exit code for incompatible licenses (for CI/CD) ``` -------------------------------- ### TOML Configuration for LicenseCheck Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Configure LicenseCheck using a `pyproject.toml` file. Specify project license, output format, custom requirement files, dependency groups, and packages/licenses to ignore or fail. ```toml # pyproject.toml configuration [tool.licensecheck] license = "mit" # Project license (auto-detected if omitted) format = "simple" # Output format: json, markdown, html, csv, ansi, simple file = "" # Output file (empty for stdout) requirements_paths = [] # Custom requirement files to read groups = [] # Dependency groups to include (e.g., ["dev", "test"]) extras = [] # Optional extras to include ignore_packages = [] # Packages to ignore (always pass) fail_packages = [] # Packages to fail (always incompatible) ignore_licenses = [] # Licenses to skip fail_licenses = [] # Licenses to fail only_licenses = [] # Whitelist of allowed licenses skip_dependencies = [] # Dependencies to skip hide_output_parameters = [] # Hide fields: name, version, size, homePage, author, license show_only_failing = false # Show only failing packages pypi_api = "https://pypi.org" # Custom PyPI endpoint zero = false # Return non-zero exit code on incompatible licenses ``` -------------------------------- ### Check Dependency License Compatibility Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/license_matrix/index.md Identifies if the end-user license is compatible with one or more dependency licenses. Supports ignoring, failing on, or only allowing specific licenses. ```python def depCompatWMyLice( myLicense: L, depLice: list[L], ignoreLicenses: list[L] | None = None, failLicenses: list[L] | None = None, onlyLicenses: list[L] | None = None, ) -> bool: ... ``` -------------------------------- ### Lookup License from String Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/license_matrix/index.md Converts an uppercase string representation of a license into its corresponding License object. Optionally ignores specified licenses. ```python def licenseLookup(licenseStr: ucstr, ignoreLicenses: list[ucstr] | None = None) -> L: ... ``` -------------------------------- ### Define RemotePackageInfo class Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Handles retrieval of package information from PyPI. ```python class RemotePackageInfo: def __init__(self, pypi_api: str, package: PackageInfo) -> None: ... ``` -------------------------------- ### Configure licensecheck with JSON Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md Defines the configuration structure for licensecheck, including license filtering and package management settings. ```json { "tool": { "licensecheck": { "extras": [], "fail_licenses": [], "fail_packages": [], "file": "", "format": "simple", "groups": [], "hide_output_parameters": [], "ignore_licenses": [], "ignore_packages": [], "license": "mit", "only_licenses": [], "pypi_api": "https://pypi.org", "requirements_paths": [], "show_only_failing": false, "skip_dependencies": [], "zero": false } } } ``` -------------------------------- ### Format License to Plain Text Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/fmt.md Use this function to format license information into a plain text string. It requires a License object and a list of package compatibilities. ```python def plainText(myLice: License, packages: list[dict[str, Any]]) -> str: ... ``` -------------------------------- ### RemotePackageInfo Class Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Handles retrieval of package information from remote sources like PyPI. ```APIDOC ## RemotePackageInfo Class [Show source in packageinfo.py:170](../../../licensecheck/packageinfo.py#L170) Handles retrieval of package info from PyPI. #### Signature ```python class RemotePackageInfo: def __init__(self, package: PackageInfo) -> None: ... ``` ### Methods #### RemotePackageInfo().get_author [Show source in packageinfo.py:197](../../../licensecheck/packageinfo.py#L197) #### Signature ```python def get_author(self) -> str | None: ... ``` #### RemotePackageInfo().get_homePage [Show source in packageinfo.py:194](../../../licensecheck/packageinfo.py#L194) #### Signature ```python def get_homePage(self) -> str | None: ... ``` #### RemotePackageInfo().get_license [Show source in packageinfo.py:177](../../../licensecheck/packageinfo.py#L177) #### Signature ```python def get_license(self) -> str | None: ... ``` #### RemotePackageInfo().get_name [Show source in packageinfo.py:184](../../../licensecheck/packageinfo.py#L184) #### Signature ```python def get_name(self) -> str | None: ... ``` #### RemotePackageInfo().get_size [Show source in packageinfo.py:200](../../../licensecheck/packageinfo.py#L200) #### Signature ```python def get_size(self) -> int: ... ``` #### RemotePackageInfo().get_version [Show source in packageinfo.py:187](../../../licensecheck/packageinfo.py#L187) #### Signature ```python def get_version(self) -> str | None: ... ``` #### RemotePackageInfo().make_req [Show source in packageinfo.py:203](../../../licensecheck/packageinfo.py#L203) #### Signature ```python def make_req(self) -> str: ... ``` #### RemotePackageInfo().poke_pypi [Show source in packageinfo.py:210](../../../licensecheck/packageinfo.py#L210) #### Signature ```python def poke_pypi(self) -> None: ... ``` ``` -------------------------------- ### Format License to HTML Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/fmt.md Use this function to format license information into an HTML string. It requires a License object and a list of package compatibilities. ```python def html(myLice: License, packages: list[dict[str, Any]]) -> str: ... ``` -------------------------------- ### LicenseCheck CI/CD Integration Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Use the `--zero` flag to ensure a non-zero exit code for incompatible licenses, enabling automated checks in CI/CD pipelines. Combine with output files for artifacts. ```bash # Return exit code 1 if incompatible licenses found licensecheck --zero ``` ```yaml # Example GitHub Actions workflow step # - name: Check Licenses # run: licensecheck --zero --only-licenses mit apache bsd ``` ```yaml # Example GitLab CI job # license-check: # script: # - pip install licensecheck # - licensecheck --zero --fail-licenses gpl agpl ``` ```bash # Combine with output file for artifacts licensecheck --zero --format json --file license-report.json ``` -------------------------------- ### depCompatWMyLice Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/license_matrix/index.md Checks if the end-user license is compatible with the provided dependency license(s). ```APIDOC ## depCompatWMyLice ### Description Identify if the end user license is compatible with the dependency license(s). ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters #### Arguments - **myLicense** (L) - Required - The end-user license to check. - **depLice** (list[L]) - Required - A list of dependency licenses. - **ignoreLicenses** (list[L], optional) - A list of licenses to ignore. Defaults to None. - **failLicenses** (list[L], optional) - A list of licenses to fail on. Defaults to None. - **onlyLicenses** (list[L], optional) - A list of allowed licenses. Defaults to None. ### Returns #### Success Response - **bool** - True if compatible, otherwise False. ### See also - [License](../types.md#license) ``` -------------------------------- ### License Check CLI Usage Source: https://github.com/fhpythonutils/licensecheck/blob/master/README.md This section outlines the command-line usage of the licensecheck tool, detailing its arguments and their purposes. ```APIDOC ## licensecheck CLI Usage ### Description Output the licenses used by dependencies and check if these are compatible with the project license. ### Method CLI Command ### Endpoint N/A ### Parameters #### Command-line Arguments - **-h, --help** (flag) - show this help message and exit - **--license LICENSE, -l LICENSE** (string) - Specify the project license explicitly, rather than rely on licensecheck interpreting this from pyproject.toml - **--format FORMAT, -f FORMAT** (string) - Output format. one of: json, markdown, html, csv, ansi, simple. default=simple - **--requirements-paths REQUIREMENTS_PATHS [REQUIREMENTS_PATHS ...], -r REQUIREMENTS_PATHS [REQUIREMENTS_PATHS ...]** (list of strings) - Filenames to read from (omit for stdin if piping, else pyproject.toml) - **--groups GROUPS [GROUPS ...], -g GROUPS [GROUPS ...]** (list of strings) - Select groups from supported files - **--extras EXTRAS [EXTRAS ...], -e EXTRAS [EXTRAS ...]** (list of strings) - Select extras from supported files - **--file FILE, -o FILE** (string) - Filename to write output to (omit this for stdout) - **--ignore-packages IGNORE_PACKAGES [IGNORE_PACKAGES ...]** (list of strings) - List of packages/dependencies to ignore (compat=True), globs are supported - **--fail-packages FAIL_PACKAGES [FAIL_PACKAGES ...]** (list of strings) - List of packages/dependencies to fail (compat=False), globs are supported - **--ignore-licenses IGNORE_LICENSES [IGNORE_LICENSES ...]** (list of strings) - List of licenses to ignore (skipped, compat may still be False) - **--fail-licenses FAIL_LICENSES [FAIL_LICENSES ...]** (list of strings) - List of licenses to fail (compat=False) - **--only-licenses ONLY_LICENSES [ONLY_LICENSES ...]** (list of strings) - List of allowed licenses (packages/dependencies with any other license will fail) - **--skip-dependencies SKIP_DEPENDENCIES [SKIP_DEPENDENCIES ...]** (list of strings) - List of packages/dependencies to skip (this sets the 'compatability' to True) - **--hide-output-parameters HIDE_OUTPUT_PARAMETERS [HIDE_OUTPUT_PARAMETERS ...]** (list of strings) - List of parameters to hide from the produced output - **--show-only-failing** (flag) - Only output a list of incompatible/ failing packages from this lib - **--pypi-api PYPI_API** (string) - Specify a custom pypi api endpoint, for example if using a custom pypi server - **--zero, -0** (flag) - Return non zero exit code if an incompatible license is found, ideal for CI/CD ### Request Example N/A ### Response N/A ``` -------------------------------- ### Define PackageInfoManager class Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/packageinfo.md Initializes the manager for handling local and remote package information retrieval. ```python class PackageInfoManager: def __init__(self, base_pypi_url: str = "https://pypi.org") -> None: ... ``` -------------------------------- ### Show only failing licenses Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/user/examples.md Use the `--show-only-failing` flag to display only packages that do not meet the specified license criteria. This is useful for identifying potential license compliance issues. ```bash >>> licensecheck --only-licenses mit apache --show-only-failing ``` -------------------------------- ### Python API: Check Dependencies for License Compatibility Source: https://context7.com/fhpythonutils/licensecheck/llms.txt Use the `checker.check()` function to programmatically verify license compatibility of project dependencies. Specify requirement paths, dependency groups, project license, and various filtering options for packages and licenses. ```python from licensecheck import checker, packageinfo, license_matrix from licensecheck.types import ucstr, License # Initialize the package info manager package_manager = packageinfo.PackageInfoManager(base_pypi_url="https://pypi.org") # Get the project license project_license = license_matrix.licenseType("MIT")[0] # Check dependencies incompatible, packages = checker.check( requirements_paths=["pyproject.toml"], groups=["dev"], # Include dev dependency group extras=[], # Optional extras this_license=project_license, # Your project's license package_info_manager=package_manager, ignore_packages=[ucstr("PYTEST")], # Packages to ignore fail_packages=[], # Packages to always fail ignore_licenses=[], # Licenses to ignore fail_licenses=[ucstr("GPL")], # Licenses to always fail only_licenses=[ucstr("MIT"), ucstr("APACHE")], # Allowed licenses only skip_dependencies=[], # Dependencies to skip ) # Process results print(f"Incompatible licenses found: {incompatible}") for pkg in sorted(packages): status = "✔" if pkg.licenseCompat else "✖" print(f"{status} {pkg.name}: {pkg.license}") # Output: # Incompatible licenses found: True # ✔ requests: APACHE SOFTWARE LICENSE # ✖ some-gpl-pkg: GPL-3.0 ``` -------------------------------- ### Check Single License Compatibility Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/license_matrix/index.md Determines if a single end-user license is compatible with a single dependency license. Can be configured with lists of licenses to ignore, fail on, or only allow. ```python def liceCompat( myLicense: L, lice: L, ignoreLicenses: list[L], failLicenses: list[L], onlyLicenses: list[L], ) -> bool: ... ``` -------------------------------- ### Format License to Raw JSON Source: https://github.com/fhpythonutils/licensecheck/blob/master/documentation/reference/licensecheck/fmt.md Use this function to format license information into a raw JSON string. It requires a License object and a list of package compatibilities. ```python def raw(myLice: License, packages: list[dict[str, Any]]) -> str: ... ```