Universal Python License Report Generator for dependency compliance analysis
Project description
License Reporter
A comprehensive, project-agnostic tool for analyzing Python project dependencies and generating license compliance reports. Perfect for legal compliance, security audits, and understanding your project's dependency landscape.
Features
-
Universal Compatibility: Supports multiple dependency specification formats:
requirements.txt(and variants likedev-requirements.txt)setup.pyandsetup.cfgpyproject.toml(PEP 621 and Poetry formats)Pipfile(Pipenv)environment.yml(Conda)
-
Intelligent Dependency Classification: Automatically distinguishes between:
- Runtime dependencies
- Development dependencies
- Optional dependencies
- Build-time tools
-
Multiple Output Formats: Generate reports in:
- Human-readable text
- JSON for programmatic processing
- Markdown for documentation
-
Smart Deduplication:
- Automatically removes duplicate packages from multiple dependency files
- Preserves the most specific version constraints
- Prioritizes runtime dependencies over development dependencies
- Maintains transparency about dependency sources
-
Advanced Filtering:
- Include/exclude development dependencies
- Runtime-only mode for PyInstaller compliance
- Pattern-based package exclusion
- Build tool filtering
-
License Analysis:
- Automatic license detection
- Attribution requirement analysis
- Unknown license identification
Installation
From PyPI (Recommended)
pip install license-reporter
From Source
git clone https://github.com/yourusername/license-reporter.git
cd license-reporter
pip install -e .
With Optional Dependencies
For enhanced functionality with YAML files:
pip install license-reporter[enhanced]
Note: TOML support is now included by default since pyproject.toml is the standard for modern Python projects.
For development:
pip install license-reporter[dev]
Quick Start
Basic Usage
# Analyze current directory
license-reporter
# Analyze specific project
license-reporter /path/to/project
# Generate JSON report
license-reporter --format json --output licenses.json
Common Use Cases
PyInstaller Compliance Report
Generate a report of only the packages that will be bundled with your PyInstaller executable:
license-reporter --runtime-only --format text --output THIRD_PARTY_LICENSES.txt
Complete Project Analysis
Include all dependencies (runtime, development, and optional):
license-reporter --all-deps --format markdown --output LICENSE_REPORT.md
Exclude Test Dependencies
license-reporter --exclude "test*,pytest*,mock*" --format json
Command Line Options
usage: license-reporter [-h] [--format {text,json,markdown}] [--output OUTPUT]
[--include-dev] [--include-optional] [--runtime-only]
[--all-deps] [--exclude EXCLUDE] [--project-name PROJECT_NAME]
[--legacy-mode]
[project_path]
positional arguments:
project_path Path to project directory (default: current directory)
optional arguments:
-h, --help show this help message and exit
--format {text,json,markdown}
Output format (default: text)
--output OUTPUT, -o OUTPUT
Output file (default: stdout)
--include-dev Include development dependencies
--include-optional Include optional dependencies
--runtime-only Include only runtime dependencies (PyInstaller compliance mode)
--all-deps Include all dependencies (runtime + dev + optional)
--exclude EXCLUDE Comma-separated list of package patterns to exclude (supports wildcards)
--project-name PROJECT_NAME
Override detected project name
--legacy-mode Use legacy OSI-specific behavior for backward compatibility
Python API
Basic Usage
from license_reporter import LicenseReporter
# Create reporter for current directory
reporter = LicenseReporter()
# Generate report
report = reporter.generate_report(
include_dev=True,
runtime_only=False,
exclude_patterns=["test*"]
)
# Access report data
print(f"Found {report['summary']['total_packages']} packages")
for package in report['packages']:
print(f"{package['name']}: {package['license']}")
Advanced Usage
from pathlib import Path
from license_reporter import LicenseReporter
from license_reporter.formatters import get_formatter
# Analyze specific project
project_path = Path("/path/to/project")
reporter = LicenseReporter(project_path)
# Generate comprehensive report
report = reporter.generate_report(
include_dev=True,
include_optional=True,
exclude_patterns=["*test*", "dev-*"],
project_name="My Project"
)
# Format as Markdown
formatter = get_formatter("markdown")
markdown_output = formatter.format(report)
# Save to file
with open("LICENSE_REPORT.md", "w") as f:
f.write(markdown_output)
Report Structure
The generated reports include:
- Project Information: Name, path, analysis type
- Summary Statistics: Package counts, attribution requirements
- Dependency Files: List of analyzed files
- Package Details: For each dependency:
- Name and version
- License information
- Author and homepage
- Attribution requirements
- Dependency type (runtime/dev/optional)
Smart Deduplication
When your project has multiple dependency files (e.g., both requirements.txt and pyproject.toml), License Reporter automatically deduplicates packages that appear in multiple files. The deduplication logic:
- Combines packages from all sources: Analyzes all discovered dependency files
- Removes duplicates by package name: Case-insensitive matching
- Preserves the most specific version: Prioritizes exact versions (
==) over ranges (>=) - Maintains dependency type priority: Runtime dependencies take precedence over dev/optional
- Tracks source information: Reports which files were analyzed
Example
If you have:
requirements.txt:requests>=2.25.0pyproject.toml:requests>=2.30.0
The final report will contain only one requests entry with version >=2.30.0 (the more restrictive constraint).
Supported File Formats
requirements.txt
requests>=2.25.0
click>=8.0.0
# Comments are ignored
-e git+https://github.com/user/repo.git#egg=package # Ignored
pyproject.toml (PEP 621)
[project]
dependencies = [
"requests>=2.25.0",
"click>=8.0.0"
]
[project.optional-dependencies]
dev = ["pytest>=7.0.0"]
pyproject.toml (Poetry)
[tool.poetry.dependencies]
python = "^3.8"
requests = "^2.25.0"
[tool.poetry.dev-dependencies]
pytest = "^7.0.0"
setup.py
setup(
name="my-project",
install_requires=[
"requests>=2.25.0",
"click>=8.0.0"
],
extras_require={
"dev": ["pytest>=7.0.0"]
}
)
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
git clone https://github.com/yourusername/license-reporter.git
cd license-reporter
pip install -e .[dev]
pre-commit install
Running Tests
pytest
Code Quality
black src tests
isort src tests
flake8 src tests
mypy src
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for a history of changes.
Support
- Issues: GitHub Issues
- Documentation: Read the Docs
- Discussions: GitHub Discussions
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_reporter-1.0.1.tar.gz.
File metadata
- Download URL: license_reporter-1.0.1.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54b27128b264019311ac44733250b8c27a058425bb545260fcf8a3c957424d4a
|
|
| MD5 |
d91c2488cdc43fda842344c0f0d995dc
|
|
| BLAKE2b-256 |
2ab7f55c18e233a11e6914c8d3f6600fe19725f046ce88693a00bc2e7ca4c319
|
File details
Details for the file license_reporter-1.0.1-py3-none-any.whl.
File metadata
- Download URL: license_reporter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc72a15a3eedd5bad7726adfb81d8ef461daa9ba4fd9d93057ebe788bdae7902
|
|
| MD5 |
18f0d40ebbd606f71720d1aad42de797
|
|
| BLAKE2b-256 |
bf9d3e306611179303c349195c4742445eca5d1ca48395be1f0f3857ef2ca082
|