https://github.com/checkmk/pyspdx
A small library to validate SPDX expressions
https://github.com/checkmk/pyspdx
Last synced: 8 months ago
JSON representation
A small library to validate SPDX expressions
- Host: GitHub
- URL: https://github.com/checkmk/pyspdx
- Owner: Checkmk
- License: gpl-2.0
- Created: 2022-09-20T15:47:17.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-10T17:08:11.000Z (over 1 year ago)
- Last Synced: 2025-09-10T18:01:18.821Z (10 months ago)
- Language: Python
- Size: 50.8 KB
- Stars: 4
- Watchers: 18
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# pyspdx
Short library to validate SPDX expressions. I have not found any working implementation in python and I wanted to mess around with pyparsing anyways.
I meanwhile found a similar library https://pypi.org/project/license-expression/.
## API / Usage
This lib only exposes two functions:
```
from pyspdx import validate, tokenize
validate("MIT") # Valid, does nothing
validate("NotValid") # Throws ValueError
validate("(Apache-2.0 OR MIT) AND BSD-3-Clause") # Valid
validate("(DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2 OR (Apache-2.0 AND PostgreSQL OR OpenSSL)) AND (BSD-3-Clause OR Apache-2.0 WITH 389-exception)") # Valid
assert tokenize("MIT") == ["MIT"]
```
## Used Sources
- https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
- https://pyparsing-docs.readthedocs.io/en/latest/HowToUsePyparsing.html