Enterprise-grade file header tool that injects repo-relative path headers into Python files
Project description
autoheader
The enterprise-grade standard for adding, refreshing, and managing repo-relative file headers.
autoheader automatically manages file headers containing repo-relative paths for source code projects. Whether you are working in a massive monorepo or a small microservice, it ensures every file is traceable, standardizing your codebase and improving developer navigation.
"Where is this file located?" — Never ask this again.
🚀 Quick Start
Prerequisites
- Python 3.8+
- Basic understanding of your project structure.
Installation
pip install "autoheader[precommit]"
Run
# Initialize and dry-run
autoheader --init && autoheader
Demo
# Copy-paste this into any file to see autoheader in action!
# src/main.py (autoheader will add this line)
import sys
print("Hello World")
✨ Features
Core
- 🌐 Polyglot Support: Manages headers for Python, JavaScript, Go, CSS, and any other language via a simple TOML configuration.
- ⚙️ Smart Setup: Get started in seconds with
autoheader --initto generate a battle-tested default configuration. - 🧩 LSP Support: Includes a Language Server (
autoheader --lsp) for real-time diagnostics directly in your IDE. - ⚡ Rich UX: Beautiful, modern output with emojis, progress bars, and visual diffs (powered by Rich).
- 🧠 Smart Copyright: Automatically updates year ranges (e.g., 2020-2025) in existing headers instead of overwriting them.
- 💻 Official SDK: Import
autoheaderin your own Python scripts (from autoheader import AutoHeader) for custom integrations. - 📂 Team Configuration: Centralize settings using
autoheader.tomlor a remote config URL (--config-url) to keep your team aligned. - 📜 Native SPDX Support: Easily use standard licenses (e.g., MIT, Apache-2.0) by setting
license_spdxin your config.
Performance
- 🚀 Parallel Execution: Supports passing specific files, parallel execution, and caching for blazing fast speed in CI pipelines.
- Smart Filtering:
.gitignoreaware, inline ignores (autoheader: ignore), and robust depth/exclusion controls.
Security
- 🛡️ Pre-commit Integration: Automatically enforce headers on every commit with
autoheader --checkor the built-in hook installer. - 🤖 GitHub Action: Use the official action
uses: dhruv13x/autoheader@v1to check headers in your CI/CD pipelines. - 🤖 Auto-Installer: Setup hooks instantly with
autoheader --install-precommitorautoheader --install-git-hook. - 🔍 SARIF Support: Output results in SARIF format (
--format sarif) for integration with GitHub Security and other scanning tools.
🛠️ Configuration
Environment Variables
| Variable | Description | Default | Required |
|---|---|---|---|
NO_COLOR |
Disable colored output if set. | None |
No |
AUTOHEADER_CONFIG |
Path to configuration file. | autoheader.toml |
No |
CLI Arguments
| Argument | Description | Default |
|---|---|---|
| Main Actions | ||
files |
Specific files to process (space separated). Scans root if empty. | (all) |
-d, --dry-run |
Preview changes without writing. | True |
-nd, --no-dry-run |
Apply changes to disk. | False |
--override |
Force rewrite of existing headers. | False |
--remove |
Remove all autoheader lines from files. | False |
| CI / Integration | ||
--check |
Exit 1 if changes needed. | False |
--check-hash |
Verify content integrity. | False |
--install-precommit |
Install pre-commit hook. |
False |
--install-git-hook |
Install native .git/hooks. |
False |
--init |
Generate default config. | False |
--lsp |
Start Language Server. | False |
| Configuration | ||
--config-url |
Remote config URL. | None |
--root |
Project root path. | cwd |
--workers |
Parallel workers. | 8 |
--timeout |
File processing timeout (s). | 60.0 |
--clear-cache |
Reset internal cache. | False |
| Filtering | ||
--depth |
Max directory scan depth. | None |
--exclude |
Glob patterns to skip. | [] |
--markers |
Project root markers. | ['.gitignore', ...] |
| Header Customization | ||
--blank-lines-after |
Blank lines after header. | 1 |
| Output | ||
--format |
default or sarif. |
default |
-v, --verbose |
Increase verbosity. | 0 |
-q, --quiet |
Suppress info output. | False |
--no-color |
Disable colors. | False |
--no-emoji |
Disable emojis. | False |
The autoheader.toml File
The primary way to configure autoheader is via the autoheader.toml file. Generate one with autoheader --init.
[general]
workers = 8
backup = false
exclude = ["tests/fixtures/*"]
[language.python]
file_globs = ["*.py"]
prefix = "# "
template = "# {path}\n#\n{license}"
license_spdx = "MIT"
Python SDK
You can use autoheader directly in your Python scripts.
from autoheader import AutoHeader
ah = AutoHeader(root=".")
# Apply headers to all files
results = ah.apply(dry_run=False)
# Check compliance
check_results = ah.check(["src/main.py"])
🏗️ Architecture
autoheader follows a strict Separation of Concerns.
src/autoheader/
├── cli.py # Entry Point: UI, args parsing, mode selection
├── api.py # The SDK: Official public API wrapper
├── core.py # Execution: File writing, diffing, safety checks
├── planner.py # The Brain: Pure business logic, decision making (PlanItem)
├── config.py # Config: TOML loading, merging, validation
├── walker.py # Discovery: File scanning, gitignore processing
├── headerlogic.py # Parsing: Header detection, SPDX handling
├── ui.py # The Face: Rich output, visual diffs
├── lsp.py # Language Server: Real-time IDE integration
└── hooks.py # Integration: Native git hook installer
Flow:
- Input: User runs CLI or SDK, providing target files and flags.
- Discovery:
walker.pyscans the file system, respecting.gitignoreandexcluderules. - Planning:
planner.pyevaluates each file in parallel against the configuration to determine the necessary action (Add, Override, Skip). - Execution:
core.pyapplies the plan, modifying files safely with optional backups. - Output:
ui.pyrenders the results to the console (or SARIF) with rich feedback.
🐞 Troubleshooting
| Issue | Solution |
|---|---|
| "Header not updating" | Check if file is excluded in .gitignore or via exclude in autoheader.toml. |
| "Permission denied" | Ensure you have write permissions to the files. Run with sudo only if necessary. |
| "LSP not working" | Ensure autoheader[lsp] is installed. Restart your IDE language server. |
| "Config not found" | Run autoheader --init to create autoheader.toml. |
| "Wrong path in header" | Check your root directory setting (--root). |
Debug Mode:
Run with autoheader -vv to see detailed debug logs, including file scanning decisions and configuration loading.
🤝 Contributing
Contributions are welcome!
Please refer to our contribution guidelines below (full CONTRIBUTING.md coming soon).
- Fork the repository.
- Clone your fork:
git clone ... - Install dev dependencies:
pip install -e ".[dev,precommit]" - Run tests:
pytest - Linting:
ruff check .
🗺️ Roadmap
We are actively building the future of code standardization.
- ✅ v9.0: Native LSP Support, Pre-commit auto-installer, Rich CLI, Official SDK, GitHub Action.
- ✅ v10.0 (Pre-release): Native Git Hook Installer, SARIF reporting, Remote Configuration.
Check ROADMAP.md for the full list of future goals like Semantic License Analysis.
License: MIT © dhruv13x
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 autoheader-10.0.1.tar.gz.
File metadata
- Download URL: autoheader-10.0.1.tar.gz
- Upload date:
- Size: 41.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
796683173e06da764a310839c8aee735a5454c69aea9b2b259c6e02bf375a146
|
|
| MD5 |
2d4def5f6c42fa3da8eea66fe9e18407
|
|
| BLAKE2b-256 |
faa342f07ec1e5ff0d4a6140b18ca72de0e7bb06429db399abdb0175dabbaaa6
|
Provenance
The following attestation bundles were made for autoheader-10.0.1.tar.gz:
Publisher:
publish.yml on dhruv13x/autoheader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autoheader-10.0.1.tar.gz -
Subject digest:
796683173e06da764a310839c8aee735a5454c69aea9b2b259c6e02bf375a146 - Sigstore transparency entry: 764296177
- Sigstore integration time:
-
Permalink:
dhruv13x/autoheader@cfd3843a6865884d7226e638aa28cbcb6218677d -
Branch / Tag:
refs/tags/v10.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfd3843a6865884d7226e638aa28cbcb6218677d -
Trigger Event:
push
-
Statement type:
File details
Details for the file autoheader-10.0.1-py3-none-any.whl.
File metadata
- Download URL: autoheader-10.0.1-py3-none-any.whl
- Upload date:
- Size: 40.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b36cece77e45db951c2165438791358bac4258168c988d982470c8e8944dd417
|
|
| MD5 |
bb387ca1a5fa406db267a29d0a7ab8bd
|
|
| BLAKE2b-256 |
70a4bcbd42b70e0a76ef799bce277cc1b90c3dd96ac33fd489192b8effbb557d
|
Provenance
The following attestation bundles were made for autoheader-10.0.1-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/autoheader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autoheader-10.0.1-py3-none-any.whl -
Subject digest:
b36cece77e45db951c2165438791358bac4258168c988d982470c8e8944dd417 - Sigstore transparency entry: 764296183
- Sigstore integration time:
-
Permalink:
dhruv13x/autoheader@cfd3843a6865884d7226e638aa28cbcb6218677d -
Branch / Tag:
refs/tags/v10.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfd3843a6865884d7226e638aa28cbcb6218677d -
Trigger Event:
push
-
Statement type: