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 (e.g., where
pyproject.tomlor.gitlives).
Installation
Install instantly via pip:
pip install "autoheader[precommit]"
Note: The
[precommit]extra is recommended for full feature support (like hook installation).
Usage Example
Scan your project and verify what needs to change (Dry Run):
# 1. Initialize a default config
autoheader --init
# 2. Preview changes (Safe by default)
autoheader
Apply the changes:
autoheader --no-dry-run
What it does: It transforms this:
import os
def main(): pass
Into this:
# src/utils/main.py
import os
def main(): pass
✨ Key Features
- 🌐 Polyglot Support: God Level. Manages headers for Python, JavaScript, Go, CSS, and any other language via a simple TOML configuration.
- 🛡️ Pre-commit Integration: God Level. Automatically enforce headers on every commit with
autoheader --checkor the built-in hook installer. - ⚙️ Smart Setup: God Level. Get started in seconds with
autoheader --initto generate a battle-tested default configuration. - 🧩 LSP Support: God Level. 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.
- 🚀 Performance: Supports passing specific files, parallel execution, and caching for blazing fast speed in CI pipelines.
- 📂 Team Configuration: Centralize settings using
autoheader.tomlor a remote config URL (--config-url) to keep your team aligned. - 💻 Official SDK: Import
autoheaderin your own Python scripts (from autoheader import AutoHeader) for custom integrations. - 🤖 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. - 📜 Native SPDX Support: Easily use standard licenses (e.g., MIT, Apache-2.0) by setting
license_spdxin your config. - Smart Filtering:
.gitignoreaware, inline ignores (autoheader: ignore), and robust depth/exclusion controls.
⚙️ Configuration & Advanced Usage
1. 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"
2. CLI Arguments
All configuration can be overridden via 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 |
3. 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"])
4. Environment Variables
While autoheader primarily uses autoheader.toml, standard environment variables like NO_COLOR=1 are respected.
5. Inline Ignores
To skip a specific file without complex config, simply add this comment anywhere in the file:
# autoheader: ignore
🏗️ 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
Core Flow:
- Initialize:
cli.pydetermines project root. - Configuration:
config.pyloads local/remote TOML. - Discovery:
walker.pyscans files, filtering byexcludeand.gitignore. - Planning:
planner.pyanalyzes files in parallel to create aPlanItem(Add, Override, Skip). - Execution:
core.pyexecutes the plan using aThreadPoolExecutor, updating files safely.
🗺️ 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.
🤝 Contributing & License
Contributions are welcome!
- Fork the repository.
- Clone:
git clone ... - Install dev deps:
pip install -e ".[dev,precommit]" - Run tests:
pytest
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.0.tar.gz.
File metadata
- Download URL: autoheader-10.0.0.tar.gz
- Upload date:
- Size: 40.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c2ac136846da7488e45e316a66acb9ae4842d860f6e59edd0a0f1804be44693
|
|
| MD5 |
1d5965fac0d4874e3829f3b18dfacaf2
|
|
| BLAKE2b-256 |
aaaff612215f5ce6ac333935bb66fe13a311ea6bc32da4b2df006fe9cda8784c
|
Provenance
The following attestation bundles were made for autoheader-10.0.0.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.0.tar.gz -
Subject digest:
5c2ac136846da7488e45e316a66acb9ae4842d860f6e59edd0a0f1804be44693 - Sigstore transparency entry: 747608941
- Sigstore integration time:
-
Permalink:
dhruv13x/autoheader@97a0f845a540a64b3bf7dd7acfc8d86829ae2af2 -
Branch / Tag:
refs/tags/v10.0.0 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@97a0f845a540a64b3bf7dd7acfc8d86829ae2af2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file autoheader-10.0.0-py3-none-any.whl.
File metadata
- Download URL: autoheader-10.0.0-py3-none-any.whl
- Upload date:
- Size: 40.3 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 |
1722ddba88cff710e0bd1ce732e290b0c6fa457615d9263b4e7521ea9b25043a
|
|
| MD5 |
3f7ecac76ff9fc426b115808215fdb02
|
|
| BLAKE2b-256 |
6e531d6f4cbcdfa8c25b7c920d7f4992926dac4da9657b4142b6f76cd340abfc
|
Provenance
The following attestation bundles were made for autoheader-10.0.0-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.0-py3-none-any.whl -
Subject digest:
1722ddba88cff710e0bd1ce732e290b0c6fa457615d9263b4e7521ea9b25043a - Sigstore transparency entry: 747608946
- Sigstore integration time:
-
Permalink:
dhruv13x/autoheader@97a0f845a540a64b3bf7dd7acfc8d86829ae2af2 -
Branch / Tag:
refs/tags/v10.0.0 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@97a0f845a540a64b3bf7dd7acfc8d86829ae2af2 -
Trigger Event:
push
-
Statement type: