Registry / data / license-expression

license-expression

JSON →
library30.4.4pypypi✓ verified 49d ago

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.

dataserialization
pip install license-expression
Install & Compatibility
Where this runs
tested against v30.4.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.056s · 19.2MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 1.6s · import 0.052s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_spdx_licensing
from license_expression import get_spdx_licensing
This function is the primary entry point for obtaining a licensing object configured with SPDX data.

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.

from license_expression import get_spdx_licensing # Get a licensing object. This can be slow and should be reused. licensing = get_spdx_licensing() # Parse a license expression expression_str = 'GPL-2.0-only OR LGPL-2.1-only AND MIT' parsed_expression = licensing.parse(expression_str) print(f"Original: {expression_str}") print(f"Parsed (pretty): {parsed_expression.pretty()}") # Check for equivalence expression_str_2 = 'MIT AND (GPL-2.0-only OR LGPL-2.1-only)' parsed_expression_2 = licensing.parse(expression_str_2) print(f"Is '{expression_str}' equivalent to '{expression_str_2}'? {licensing.is_equivalent(parsed_expression, parsed_expression_2)}") # Validate an expression valid = licensing.validate(expression_str) print(f"Is '{expression_str}' a valid expression? {valid.errors if valid.errors else True}") invalid_expression = 'Invalid-License AND Other-License' invalid_valid = licensing.validate(invalid_expression) print(f"Is '{invalid_expression}' a valid expression? {invalid_valid.errors if invalid_valid.errors else True}")
Debug
Known issues
breakingSupport 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.
fix
Upgrade Python to 3.9 or newer.
affects: >=30.4.0
breakingSupport 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.
fix
Upgrade Python to 3.8 or newer.
affects: >=30.3.0
gotchaVersion 30.4.2 was released with missing wheels, which could lead to installation issues. This was corrected in version 30.4.3.
fix
Avoid installing version 30.4.2; install version 30.4.3 or later instead.
affects: 30.4.2
gotchaThe `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.
fix
Cache and reuse the `licensing` object returned by `get_spdx_licensing()`.
affects: All
gotchaThe 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.
fix
Update any hardcoded GitHub repository URLs from `nexB/license-expression` to `aboutcode-org/license-expression`.
affects: All versions referencing the old GitHub URL
Errors
Common errors & fixes
ExpressionError: Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'MIT/X11'
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.
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.
ModuleNotFoundError: No module named 'license_expression'
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.
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`.
Unknown license key(s)
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.
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.
Upgrade
Version history
30.4.4latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
4
ahrefsbot
3
seranking-bot
3
Resources