{"id":1108,"library":"license-expression","title":"License-Expression","description":"license-expression is a comprehensive Python utility library designed to parse, compare, simplify, and normalize license expressions, particularly SPDX license expressions, using boolean logic. It actively maintains and updates its bundled license keys from the SPDX License List and ScanCode LicenseDB, with frequent patch releases for these updates and minor releases for broader changes.","status":"active","version":"30.4.4","language":"python","source_language":"en","source_url":"https://github.com/aboutcode-org/license-expression","tags":["license","spdx","expression","parsing","validation","compliance"],"install":[{"cmd":"pip install license-expression","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This function is the primary entry point for obtaining a licensing object configured with SPDX data.","symbol":"get_spdx_licensing","correct":"from license_expression import get_spdx_licensing"}],"quickstart":{"code":"from license_expression import get_spdx_licensing\n\n# Get a licensing object. This can be slow and should be reused.\nlicensing = get_spdx_licensing()\n\n# Parse a license expression\nexpression_str = 'GPL-2.0-only OR LGPL-2.1-only AND MIT'\nparsed_expression = licensing.parse(expression_str)\n\nprint(f\"Original: {expression_str}\")\nprint(f\"Parsed (pretty): {parsed_expression.pretty()}\")\n\n# Check for equivalence\nexpression_str_2 = 'MIT AND (GPL-2.0-only OR LGPL-2.1-only)'\nparsed_expression_2 = licensing.parse(expression_str_2)\nprint(f\"Is '{expression_str}' equivalent to '{expression_str_2}'? {licensing.is_equivalent(parsed_expression, parsed_expression_2)}\")\n\n# Validate an expression\nvalid = licensing.validate(expression_str)\nprint(f\"Is '{expression_str}' a valid expression? {valid.errors if valid.errors else True}\")\n\ninvalid_expression = 'Invalid-License AND Other-License'\ninvalid_valid = licensing.validate(invalid_expression)\nprint(f\"Is '{invalid_expression}' a valid expression? {invalid_valid.errors if invalid_valid.errors else True}\")","lang":"python","description":"This quickstart demonstrates how to initialize the SPDX licensing engine and use it to parse, pretty-print, check equivalence, and validate license expressions. The `get_spdx_licensing()` call can be computationally intensive, so its result should be cached and reused."},"warnings":[{"fix":"Upgrade Python to 3.9 or newer.","message":"Support for Python 3.8 was dropped in version 30.4.0. Users on Python 3.8 or older must upgrade their Python environment to Python 3.9 or newer to use the latest versions of license-expression.","severity":"breaking","affected_versions":">=30.4.0"},{"fix":"Upgrade Python to 3.8 or newer.","message":"Support for Python 3.7 was dropped in version 30.3.0. Users on Python 3.7 or older must upgrade their Python environment to Python 3.8 or newer (preferably 3.9+) to use these versions.","severity":"breaking","affected_versions":">=30.3.0"},{"fix":"Avoid installing version 30.4.2; install version 30.4.3 or later instead.","message":"Version 30.4.2 was released with missing wheels, which could lead to installation issues. This was corrected in version 30.4.3.","severity":"gotcha","affected_versions":"30.4.2"},{"fix":"Cache and reuse the `licensing` object returned by `get_spdx_licensing()`.","message":"The `get_spdx_licensing()` function, which initializes the license parsing engine, can be slow to execute due to loading license data. It is recommended to call this function once and reuse the returned `licensing` object throughout your application for performance.","severity":"gotcha","affected_versions":"All"},{"fix":"Update any hardcoded GitHub repository URLs from `nexB/license-expression` to `aboutcode-org/license-expression`.","message":"The library's GitHub organization moved from 'nexB' to 'aboutcode-org' around version 30.3.1. While the `pypi` package name remains `license-expression`, any direct references to the GitHub repository in CI/CD or other tools should be updated.","severity":"gotcha","affected_versions":"All versions referencing the old GitHub URL"}],"env_vars":null,"search_vec":"'activ':30 'boolean':27 'broader':57 'bundl':35 'chang':58 'compar':16 'complianc':64 'comprehens':9 'design':13 'express':3,6,21,25,61 'frequent':47 'key':37 'librari':12 'licens':2,5,20,24,36,41,59 'license-express':1,4 'licensedb':45 'list':42 'logic':28 'maintain':31 'minor':54 'normal':19 'pars':15,62 'particular':22 'patch':48 'python':10 'releas':49,55 'scancod':44 'simplifi':17 'spdx':23,40,60 'updat':33,52 'use':26 'util':11 'valid':63","created_at":"2026-04-05T13:06:03.162574+00:00","updated_at":"2026-04-16T16:13:52.129225+00:00","problems":[{"fix":"Ensure license keys are valid SPDX identifiers (e.g., 'MIT', 'Apache-2.0') and the expression strictly follows SPDX syntax, using valid operators like 'AND', 'OR', 'WITH', and adhering to specified character rules.","cause":"The license expression provided contains characters or a format that is not compliant with the SPDX specification or the library's allowed characters for license keys.","error":"ExpressionError: Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'MIT/X11'"},{"fix":"Install the library using pip: `pip install license-expression`. If already installed, ensure the correct Python environment is activated or use the standard import: `from license_expression import get_spdx_licensing`.","cause":"The 'license-expression' library is either not installed in the current Python environment, the environment is not activated, or there is a typo in the import statement.","error":"ModuleNotFoundError: No module named 'license_expression'"},{"fix":"Refer to the official SPDX License List (https://spdx.org/licenses/) and use the exact short-form identifiers (e.g., 'GPL-2.0-only' instead of 'GPL2') in your license expressions.","cause":"When validating a license expression using `licensing.validate()`, one or more license identifiers within the expression are not recognized as valid SPDX license keys by the library's bundled license data.","error":"Unknown license key(s)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"30.4.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/aboutcode-org/license-expression","docs":null,"changelog":null,"pypi":"https://pypi.org/project/license-expression/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}