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.1.tar.gz (29.7 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.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file license_analyzer-0.0.1.tar.gz.

File metadata

  • Download URL: license_analyzer-0.0.1.tar.gz
  • Upload date:
  • Size: 29.7 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.1.tar.gz
Algorithm Hash digest
SHA256 2076b02c2823198a5308bcbcc34ad1773241ae27faba5f6bf2abeaa9d676b1d7
MD5 a71893412badeb02ca22eb190dfc8969
BLAKE2b-256 d6d1eabc5b8695388684e625fa802ef8a5cb749867a50071aa539f79639c5d6e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for license_analyzer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78a92e17025f48b44a90348ff0f7e05f3d47a2dba7347681854ae90edcdf3103
MD5 9c4eb95d4c646fa84c57517abda57a1b
BLAKE2b-256 71dd44e491aee46e18081525170ee5b28ccbee7d29acb9ea5828d7e38788e7ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for license_analyzer-0.0.1-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