A robust Python module for analyzing and comparing software licenses
Project description
license-analyzer
SPDX license identification using hashes, fingerprints, and semantic similarity.
Supports command-line usage as well as Python module integration.
📦 Installation
pip install license-analyzer
To install from source (e.g., for development):
git clone https://github.com/yourorg/license-analyzer.git
cd license-analyzer
pip install .
🚀 Command-Line Usage
Once installed, the CLI tool is available as:
license-analyzer [OPTIONS] FILE [FILE...]
🔧 Common Options
| Option | Description |
|---|---|
--top-n N |
Return top N matches per file. If omitted, returns all matches tied for highest score. |
--format {text,json,csv} |
Output format. Default is text. |
--min-score FLOAT |
Filter out matches with a score below this threshold (default: 0.0). |
--spdx-dir DIR |
Path to SPDX license text files. Defaults to ~/.cache/license-analyzer/spdx/text. |
--cache-dir DIR |
Path to cache directory for license database. |
--embedding-model NAME |
SentenceTransformer model (default: all-MiniLM-L6-v2). |
--update, -u |
Force update of SPDX license data from GitHub. |
--verbose, -v |
Show progress and debug logs. |
📄 Examples
Basic usage
license-analyzer LICENSE
Multiple files
license-analyzer license1.txt license2.txt
JSON output with top 3 matches
license-analyzer --format json --top-n 3 LICENSE
Force SPDX update
license-analyzer --update
🐍 Python Module Usage
You can also use license-analyzer directly in your Python code:
from license_analyzer.core import LicenseAnalyzer
analyzer = LicenseAnalyzer()
matches = analyzer.analyze_file("LICENSE")
for match in matches:
print(match.name, match.score, match.method)
Or, if you want to analyze text (rather than a file):
text = open("LICENSE").read()
matches = analyzer.analyze_text(text)
for match in matches:
print(match.name, match.score, match.method)
Use top_n=None to get all tied top-scoring matches:
matches = analyzer.analyze_text(text, top_n=None)
📈 Output Format (CLI)
Text (default)
Analysis results for: LICENSE
------------------------------------------------------------
MIT score: 1.0000 method: sha256
JSON
{
"LICENSE": [
{
"name": "MIT",
"score": 1.0,
"method": "sha256"
}
]
}
CSV
file_path,license_name,score,method
"LICENSE","MIT",1.0,"sha256"
🔄 Updating SPDX License Data
By default, license data is stored under:
~/.cache/license-analyzer/spdx
To update the SPDX license texts (from GitHub):
license-analyzer --update
This refreshes cached licenses and triggers database rebuild if needed.
🧠 Matching Strategies
- ✅ SHA256 Hash Match
- ✅ Canonical Fingerprint Match
- ✅ Semantic Embedding Match (via sentence-transformers)
📝 License
SPDX-License-Identifier: Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file license_analyzer-0.0.4.tar.gz.
File metadata
- Download URL: license_analyzer-0.0.4.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f43e968c664e5da9f28a0668bf3bcee41fdc39ab42a74c754bb8d5643667ba
|
|
| MD5 |
66cc6c15082018c04a9076c36796568f
|
|
| BLAKE2b-256 |
54b25b546dd685e52ae2ab6970fccbac346eb72ff84a7200c96b83f5933f63c4
|
Provenance
The following attestation bundles were made for license_analyzer-0.0.4.tar.gz:
Publisher:
pypi-publish.yml on envolution/license-analyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
license_analyzer-0.0.4.tar.gz -
Subject digest:
a9f43e968c664e5da9f28a0668bf3bcee41fdc39ab42a74c754bb8d5643667ba - Sigstore transparency entry: 238774217
- Sigstore integration time:
-
Permalink:
envolution/license-analyzer@88f8cd36f26b33285905e59d65e8ac9fc91afb09 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@88f8cd36f26b33285905e59d65e8ac9fc91afb09 -
Trigger Event:
release
-
Statement type:
File details
Details for the file license_analyzer-0.0.4-py3-none-any.whl.
File metadata
- Download URL: license_analyzer-0.0.4-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c8cb9027fbdefba6f83a0e314ee45e43173afc518f8db2a19dffb5ce58d4e5
|
|
| MD5 |
09d1cf16c2ccfd5e210a4d9db29e64fc
|
|
| BLAKE2b-256 |
aae8113461bf8df9294ff869bad5ce8b1cf9c23475b1d9d0778bab4de9d598ec
|
Provenance
The following attestation bundles were made for license_analyzer-0.0.4-py3-none-any.whl:
Publisher:
pypi-publish.yml on envolution/license-analyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
license_analyzer-0.0.4-py3-none-any.whl -
Subject digest:
96c8cb9027fbdefba6f83a0e314ee45e43173afc518f8db2a19dffb5ce58d4e5 - Sigstore transparency entry: 238774218
- Sigstore integration time:
-
Permalink:
envolution/license-analyzer@88f8cd36f26b33285905e59d65e8ac9fc91afb09 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@88f8cd36f26b33285905e59d65e8ac9fc91afb09 -
Trigger Event:
release
-
Statement type: