Skip to main content

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

  1. LicenseAnalyzer: Main interface class
  2. LicenseDatabase: Manages license data with lazy loading
  3. LicenseMatch: Represents analysis results
  4. DatabaseEntry: Internal license database entry
  5. MatchMethod: Enumeration of matching strategies

Matching Strategies

  1. SHA256: Exact byte-for-byte matching (fastest, most accurate)
  2. Fingerprint: Canonical token-based matching (handles formatting differences)
  3. 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


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.3.tar.gz (27.6 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.3-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

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

Hashes for license_analyzer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8cf8cd79081ba5b4d50faf5fbf217269d3e6d8119177904f1e08f03ff541d251
MD5 c97c0b4160eb8a7026678ca5613fa73c
BLAKE2b-256 25f804c8513cd1ac80821ff1f35df1f83eb8eca50eddc5e3b6315cd57519b219

See more details on using hashes here.

Provenance

The following attestation bundles were made for license_analyzer-0.0.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for license_analyzer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 214ac74fe0b265c1f5eb1af1df94755390049abc63b9edc34d648df624be6de4
MD5 7987befbd56645eecb7e4a8c228542df
BLAKE2b-256 692df55767e06766f2ffe3bd401ebf86e63c9f05f795b60f532bf626f0d6f445

See more details on using hashes here.

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

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