py-license-auditor
A fast, reliable command-line tool to extract and analyze license information from Python packages installed in your environment.
✨ Features
- 🔍 Comprehensive Detection: Extracts license info from
.dist-infoand.egg-infodirectories - 📊 Multiple Output Formats: JSON, TOML, and CSV support
- 🎯 Smart Categorization: Separates OSI-approved from non-OSI licenses
- 📈 Usage Statistics: Shows license distribution with counts
- 🚀 Fast Performance: Written in Rust for speed
- 🔧 CI/CD Ready: Perfect for automated license compliance checks
- ⚖️ License Violation Detection: Automatically detect policy violations with customizable rules
- 🚨 Policy Enforcement: Fail builds on forbidden licenses for compliance automation
- 🎛️ Flexible Configuration: TOML-based policy files with exact matching and glob patterns
🚀 Installation
From crates.io (Recommended)
From source
📖 Usage
📚 Quick Start: See QUICKSTART.md for a step-by-step guide
Quick Start
# Auto-detect .venv in current directory
# Specify site-packages directory
# Save to file
Output Formats
# JSON (default)
# TOML
# CSV for spreadsheets
Advanced Options
# Include packages without license info
# Combine options
License Violation Detection
# Use built-in policies (no setup required)
# Use custom policy file
# Fail build on forbidden licenses (for CI/CD)
# Generate compliance report with violations
📊 Output Example
JSON Format
}
}
CSV Format
name,version,license,license_classifiers,metadata_source
requests,2.31.0,Apache-2.0,"License :: OSI Approved :: Apache Software License",METADATA
click,8.1.7,BSD-3-Clause,"License :: OSI Approved :: BSD License",METADATA
🎛️ Policy Configuration
Built-in Policies
Three ready-to-use policies are included:
# Corporate: Conservative policy for proprietary software
# Permissive: Balanced policy for open source projects
# Strict: Very restrictive - only MIT, Apache-2.0, BSD-3-Clause
| Policy | Allowed | Forbidden | Review Required |
|---|---|---|---|
| Corporate | MIT, Apache-2.0, BSD-* | GPL-, AGPL-, LGPL-* | MPL-2.0 |
| Permissive | MIT, Apache-2.0, BSD-*, MPL-2.0 | None | GPL-, AGPL- |
| Strict | MIT, Apache-2.0, BSD-3-Clause | GPL-, AGPL-, LGPL-*, MPL-2.0 | ISC, BSD-* |
Custom Policy File Format
Create a policy.toml file to define your license compliance rules:
= "Corporate License Policy"
= "License policy for proprietary software development"
[]
= ["MIT", "Apache-2.0", "BSD-3-Clause", "ISC"]
= ["BSD-*"]
[]
= ["GPL-3.0", "AGPL-3.0"]
= ["GPL-*", "AGPL-*"]
[]
= ["MPL-2.0", "LGPL-2.1"]
= ["LGPL-*"]
[[]]
= "legacy-package"
= "1.0.0"
= "Approved by legal team for legacy compatibility"
Policy Rules
- allowed_licenses: Licenses that are automatically approved
- forbidden_licenses: Licenses that cause build failures
- review_required: Licenses that need manual review (warnings)
- exceptions: Package-specific overrides with justification
Pattern Matching
Use glob patterns for flexible license matching:
"GPL-*"matchesGPL-2.0,GPL-3.0, etc."BSD-*"matchesBSD-2-Clause,BSD-3-Clause, etc.
🎯 Use Cases
License Compliance
Generate comprehensive reports for legal review and compliance auditing.
# Generate compliance report
CI/CD Integration
Automate license checking in your deployment pipeline.
# GitHub Actions example
- name: Check license compliance
run: |
py-license-auditor --policy corporate --check-violations --fail-on-violations
- name: Generate license report
run: |
py-license-auditor --format json --output license-report.json
# Basic license extraction
Dependency Auditing
Understand your project's license obligations and risks.
# Focus on non-OSI licenses that need manual review
|
🔍 License Categories
The tool categorizes licenses into two groups:
- OSI Approved: Licenses approved by the Open Source Initiative (legally vetted)
- Non-OSI: Custom licenses, proprietary licenses, or unrecognized formats
This helps you quickly identify which licenses need manual legal review.
🛠️ Development
Building from Source
Running Tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.