Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

license_analyzer-0.0.4.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

license_analyzer-0.0.4-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

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

Hashes for license_analyzer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a9f43e968c664e5da9f28a0668bf3bcee41fdc39ab42a74c754bb8d5643667ba
MD5 66cc6c15082018c04a9076c36796568f
BLAKE2b-256 54b25b546dd685e52ae2ab6970fccbac346eb72ff84a7200c96b83f5933f63c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for license_analyzer-0.0.4.tar.gz:

Publisher: pypi-publish.yml on envolution/license-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file license_analyzer-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for license_analyzer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 96c8cb9027fbdefba6f83a0e314ee45e43173afc518f8db2a19dffb5ce58d4e5
MD5 09d1cf16c2ccfd5e210a4d9db29e64fc
BLAKE2b-256 aae8113461bf8df9294ff869bad5ce8b1cf9c23475b1d9d0778bab4de9d598ec

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page