A robust Python module for analyzing and comparing software licenses
Project description
License Analyzer
A robust Python module for analyzing and comparing software licenses using multiple matching strategies including SHA256, fingerprinting, and semantic embeddings.
Features
- Multiple Matching Methods: SHA256 exact matching, canonical fingerprinting, and semantic embeddings
- Lazy Loading: Embedding models are only loaded when needed for performance
- Efficient Caching: Automatically manages license database with incremental updates
- Batch Processing: Analyze multiple license files in a single operation
- Flexible API: Both object-oriented and functional interfaces
- Command Line Interface: Easy-to-use CLI for quick analysis
- Comprehensive Testing: Full test suite with mocking for reliable operation
Installation
# Install from PyPI (when published)
pip install license-analyzer
# Or install from source
git clone https://github.com/yourusername/license-analyzer.git
cd license-analyzer
pip install -e .
# For development
pip install -e .[dev]
Requirements
- Python 3.8+
- numpy
- sentence-transformers (for semantic analysis)
- torch (dependency of sentence-transformers)
Quick Start
As a Library
from license_analyzer import LicenseAnalyzer
# Initialize analyzer
analyzer = LicenseAnalyzer()
# Analyze a single file
matches = analyzer.analyze_file("LICENSE.txt", top_n=5)
for match in matches:
print(f"{match.name}: {match.score:.4f} ({match.method.value})")
# Analyze text directly
license_text = """MIT License
Copyright (c) 2024 Your Name
Permission is hereby granted..."""
matches = analyzer.analyze_text(license_text)
print(f"Best match: {matches[0].name} (score: {matches[0].score:.4f})")
# Analyze multiple files
results = analyzer.analyze_multiple_files([
"LICENSE1.txt",
"LICENSE2.txt",
"LICENSE3.txt"
])
for file_path, matches in results.items():
print(f"\n{file_path}:")
for match in matches[:3]: # Top 3 matches
print(f" {match.name}: {match.score:.4f}")
Command Line Interface
# Analyze a single file
license-analyzer LICENSE.txt
# Analyze multiple files
license-analyzer LICENSE1.txt LICENSE2.txt LICENSE3.txt
# Get top 10 matches in JSON format
license-analyzer --format json --top-n 10 LICENSE.txt
# Set minimum score threshold
license-analyzer --min-score 0.8 LICENSE.txt
# Use custom SPDX directory
license-analyzer --spdx-dir /custom/path/spdx LICENSE.txt
# Verbose output with database stats
license-analyzer --verbose LICENSE.txt
Architecture
Core Components
- LicenseAnalyzer: Main interface class
- LicenseDatabase: Manages license data with lazy loading
- LicenseMatch: Represents analysis results
- DatabaseEntry: Internal license database entry
- MatchMethod: Enumeration of matching strategies
Matching Strategies
- SHA256: Exact byte-for-byte matching (fastest, most accurate)
- Fingerprint: Canonical token-based matching (handles formatting differences)
- Embedding: Semantic similarity using sentence transformers (most flexible)
Performance Optimization
- Lazy Loading: Embedding models are only loaded when needed
- Incremental Updates: Database only processes changed files
- Smart Matching: Perfect matches skip expensive embedding computation
- Efficient Caching: JSON-based database with SHA
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.3.tar.gz.
File metadata
- Download URL: license_analyzer-0.0.3.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cf8cd79081ba5b4d50faf5fbf217269d3e6d8119177904f1e08f03ff541d251
|
|
| MD5 |
c97c0b4160eb8a7026678ca5613fa73c
|
|
| BLAKE2b-256 |
25f804c8513cd1ac80821ff1f35df1f83eb8eca50eddc5e3b6315cd57519b219
|
Provenance
The following attestation bundles were made for license_analyzer-0.0.3.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.3.tar.gz -
Subject digest:
8cf8cd79081ba5b4d50faf5fbf217269d3e6d8119177904f1e08f03ff541d251 - Sigstore transparency entry: 238559312
- Sigstore integration time:
-
Permalink:
envolution/license-analyzer@be46316e2c133176604d692e269f21b1ef46cc06 -
Branch / Tag:
refs/tags/0.0.3 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@be46316e2c133176604d692e269f21b1ef46cc06 -
Trigger Event:
release
-
Statement type:
File details
Details for the file license_analyzer-0.0.3-py3-none-any.whl.
File metadata
- Download URL: license_analyzer-0.0.3-py3-none-any.whl
- Upload date:
- Size: 22.5 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 |
214ac74fe0b265c1f5eb1af1df94755390049abc63b9edc34d648df624be6de4
|
|
| MD5 |
7987befbd56645eecb7e4a8c228542df
|
|
| BLAKE2b-256 |
692df55767e06766f2ffe3bd401ebf86e63c9f05f795b60f532bf626f0d6f445
|
Provenance
The following attestation bundles were made for license_analyzer-0.0.3-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.3-py3-none-any.whl -
Subject digest:
214ac74fe0b265c1f5eb1af1df94755390049abc63b9edc34d648df624be6de4 - Sigstore transparency entry: 238559315
- Sigstore integration time:
-
Permalink:
envolution/license-analyzer@be46316e2c133176604d692e269f21b1ef46cc06 -
Branch / Tag:
refs/tags/0.0.3 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@be46316e2c133176604d692e269f21b1ef46cc06 -
Trigger Event:
release
-
Statement type: