Auto-generate missing __init__.py files to fix Python import issues and ensure proper module discovery.
Project description
pyinitgen
Automated init.py generator for Python packages Ensures every directory in your project is a proper Python package — no more mysterious ModuleNotFoundError surprises.
Perfect for:
Large refactors
Monorepos / multi-package architectures
Auto-generated project structures
Migration from namespace-less directories
CI environments ensuring package integrity
🚀 Features
| Feature | Description |
|---|---|
| 📂 Recursive Scan | Walks the directory tree intelligently to find all Python modules. |
🛠️ Auto-creates __init__.py |
Creates __init__.py files only where they are missing. |
| 🧠 Smart Exclusions | Ignores common system and runtime directories by default. |
| 📝 Customized Ignores | Supports a .pyinitgenignore file to add your own exclusion rules. |
| ✍️ Custom Content | Lets you write custom content to newly created __init__.py files. |
| 👀 Dry-Run Mode | Preview which __init__.py files will be created without writing them. |
| 🎯 Project-safe | Avoids touching non-Python folders and respects your project structure. |
| ✨ Emoji Status | Provides an optional, fancy terminal UX with emoji status indicators. |
| 🔒 Zero Destructive Actions | Never overwrites existing files or content. |
📦 Installation
pip install pyinitgen
⚙️ Configuration & Advanced Usage
CLI Arguments
| Argument | Short | Description | Default |
|---|---|---|---|
--base-dir <path> |
Base directory to scan. | . |
|
--dry-run |
Preview changes without writing to disk. | false |
|
--quiet |
-q |
Suppress all non-error output. | false |
--verbose |
-v |
Show all scanned directories. | false |
--no-emoji |
Disable emoji in the final output. | false |
|
--init-content "..." |
Custom content to write to new __init__.py files. |
"" |
|
--version |
Show the program's version number and exit. |
Customizing Exclusions with .pyinitgenignore
To exclude specific directories from being scanned, create a .pyinitgenignore file in your project's root directory. Each line in this file is treated as a pattern to be excluded.
Note: This feature is ideal for excluding auto-generated folders, data directories, or any other project-specific directories that should not be treated as Python packages.
Example .pyinitgenignore:
# .pyinitgenignore
# Exclude the entire 'assets' directory
assets
# Exclude any directories named 'legacy'
legacy
📝 Example Output
Scanning: src/utils Created src/utils/init.py ✅ Operation complete. Scanned 43 dirs, created 8 new init.py files.
🧩 Why this tool?
Problem Solution
Large Python codebases without -inits Auto insert all required files ModuleNotFoundError during import Ensures folders become packages Hand-creating 50+ init.py files One command 🤖 Accidental file writes? Only creates missing files
⚙️ CLI Help
pyinitgen --help
🛡️ Safe by Design
Never touches existing files
Ignores system & irrelevant dirs by default
Supports dry-run to preview
💡 Tip
Use in CI to guarantee package consistency:
pyinitgen --dry-run
🏗️ Architecture
The project is structured as a standard Python CLI application:
src/
└── pyinitgen/
├── __init__.py
├── banner.py # Renders the ASCII logo
└── cli.py # Core logic and CLI argument parsing
The core logic resides in cli.py, which performs the directory scan and __init__.py file creation. The banner.py module is a purely cosmetic addition to improve the user experience.
🗺️ Roadmap
- Add support for customizing the default exclusion list via a configuration file.
- Implement a
--watchmode to automatically create__init__.pyfiles as new directories are created. - Add a
--checkflag that will exit with a non-zero status code if any__init__.pyfiles are missing, but will not create them.
🤝 Contributing
PRs welcome — improve detection logic, add custom exclusion rules, enhance output UX.
👉 Repo: https://github.com/dhruv13x/pyinitgen
📜 License
MIT
🧭 Related Tools in the Suite
Tool Purpose
importdoc Import issue diagnosis import-surgeon Safe import refactoring pypurge Clean caches, venv junk pyinitgen Generate missing init.py ✅ (this project)
⭐ Support
If you like this tool:
⭐ Star the GitHub repo
🐍 Use it in CI & projects
📦 Recommend to Python dev friends
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
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 pyinitgen-3.0.2.tar.gz.
File metadata
- Download URL: pyinitgen-3.0.2.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0721b079e7283a0a2da15e8225fa1252d6b635eae0c4e4fed7d0bd222ab80ec8
|
|
| MD5 |
8fc9ba5ea19662b283ec00806b603815
|
|
| BLAKE2b-256 |
ec296ee3a981e0dc826fa178694bbf827b18083cd1cc38c72b3757dc57efd75f
|
Provenance
The following attestation bundles were made for pyinitgen-3.0.2.tar.gz:
Publisher:
publish.yml on dhruv13x/pyinitgen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyinitgen-3.0.2.tar.gz -
Subject digest:
0721b079e7283a0a2da15e8225fa1252d6b635eae0c4e4fed7d0bd222ab80ec8 - Sigstore transparency entry: 725340187
- Sigstore integration time:
-
Permalink:
dhruv13x/pyinitgen@e919f0af04c4e70aa1bbb76c43bc5cdc3b13ffe2 -
Branch / Tag:
refs/tags/v3.0.2 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e919f0af04c4e70aa1bbb76c43bc5cdc3b13ffe2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyinitgen-3.0.2-py3-none-any.whl.
File metadata
- Download URL: pyinitgen-3.0.2-py3-none-any.whl
- Upload date:
- Size: 9.0 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 |
aecd7f836151fc9cff0658a1b8c9b2334405ca067a210328829b05cf934a5932
|
|
| MD5 |
89c20360365a969fd7c6d9ce991b61aa
|
|
| BLAKE2b-256 |
cc898aaa91b471273bb0ea6f0ae751eb71e62f5eb1633af6dadc3e95cf38fdbf
|
Provenance
The following attestation bundles were made for pyinitgen-3.0.2-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/pyinitgen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyinitgen-3.0.2-py3-none-any.whl -
Subject digest:
aecd7f836151fc9cff0658a1b8c9b2334405ca067a210328829b05cf934a5932 - Sigstore transparency entry: 725340207
- Sigstore integration time:
-
Permalink:
dhruv13x/pyinitgen@e919f0af04c4e70aa1bbb76c43bc5cdc3b13ffe2 -
Branch / Tag:
refs/tags/v3.0.2 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e919f0af04c4e70aa1bbb76c43bc5cdc3b13ffe2 -
Trigger Event:
push
-
Statement type: