Skip to main content
pyinitgen logo

pyinitgen

Auto-generate missing __init__.py files to fix Python import issues and ensure proper module discovery.

PyPI version Python License Code Style: Black Build Status Maintenance


⚡ Quick Start

Prerequisites

  • Python 3.8 or higher

Installation

pip install pyinitgen

Run

Navigate to your project root and run:

pyinitgen

Demo

# Preview changes without writing (Safe Mode)
pyinitgen --dry-run

# Run and fix your project structure
pyinitgen
# Output:
# Created src/utils/__init__.py
# ✅ Operation complete. Scanned 43 dirs, created 8 new __init__.py files.

✨ Features

  • 📂 Recursive Scan: Intelligently walks your directory tree to find all Python module folders.
  • 🛠️ Auto-creates __init__.py: Generates files only where they are missing.
  • 🧠 Smart Exclusions: Automatically ignores node_modules, .git, __pycache__, venv, and other non-Python directories.
  • ✍️ Custom Content: Inject custom code (e.g., license headers) into every new __init__.py.
  • 👀 Dry-Run Mode: Visualize changes before applying them.
  • ✅ Check Flag: CI/CD ready—exit with an error if files are missing without modifying disk.
  • 🔒 Zero Destructive Actions: Never overwrites existing files.

🛠️ Configuration

Environment Variables

Name Description Default Required
CREATE_DUMP_PALETTE Select a fixed color palette index (0-5) for the logo. None (Procedural) No

CLI Arguments

Flag Short Description
--base-dir Base directory to scan (default: current directory).
--dry-run Preview changes without writing to disk.
--quiet -q Suppress all non-error output.
--verbose -v Show all scanned directories (debug mode).
--no-emoji Disable emoji in the final output.
--init-content Custom content to write to new __init__.py files.
--check Check for missing __init__.py files and exit with code 1 if found.
--version Show the program's version number and exit.

Configuration Files

You can define permanent exclusions in pyproject.toml or .pyinitgen.toml.

pyproject.toml example:

[tool.pyinitgen]
exclude_dirs = ["legacy_code", "test_data"]

.pyinitgenignore example: Create a .pyinitgenignore file in your root to list folders to skip (one per line).

assets
legacy
temp_builds

🏗️ Architecture

pyinitgen follows a standard Python CLI structure designed for maintainability and speed.

src/
└── pyinitgen/
    ├── __init__.py
    ├── banner.py   # 🎨 Renders the procedural ASCII art logo
    ├── cli.py      # 🧠 Core logic: Scan, Detect, Create
    ├── config.py   # ⚙️ Configuration loader (TOML handling)
    └── ignores.py  # 🚫 Ignore pattern processing

Data Flow:

  1. CLI Entry: Arguments are parsed.
  2. Config Load: Global config, local TOML files, and .pyinitgenignore are merged.
  3. Walker: Directory tree is traversed, filtering out excluded paths.
  4. Creator: Missing __init__.py files are identified and created (or reported in Dry Run).

🐞 Troubleshooting

Error Message Possible Cause Solution
ModuleNotFoundError: No module named 'rich' Missing dependency. Run pip install pyinitgen --upgrade.
Permission denied: '.../__init__.py' File system permissions. Run with appropriate permissions or check folder ownership.
No files created Directories might be ignored. Check pyproject.toml or .pyinitgenignore exclusions. Use -v to debug.

Debug Mode: Use the verbose flag to see exactly what directories are being scanned:

pyinitgen -v --dry-run

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on how to set up your development environment, run tests, and submit PRs.

Development Setup

  1. Clone the repo.
  2. Install dev dependencies: pip install -e ".[dev]"
  3. Run tests: python -m pytest tests/

🗺️ Roadmap

  • Custom Exclusions: Support for config files.
  • CI/CD Check: --check flag for pipelines.
  • Watch Mode: Auto-generate files as directories are created.
  • Interactive Mode: Confirm each file creation.

Metadata

Release files for pyinitgen 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyinitgen 4.0.1
File Size Uploaded Provenance Actions
pyinitgen-4.0.1.tar.gz 15.4 kB With provenance Details for pyinitgen-4.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyinitgen 4.0.1
File Interpreter ABI Platform Actions
pyinitgen-4.0.1-py3-none-any.whl Python 3 none any Details for pyinitgen-4.0.1-py3-none-any.whl

Total release size: 25.3 kB

Release files / pyinitgen-4.0.1.tar.gz

Download URL pyinitgen-4.0.1.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
43621dcba8bf42908fbeb76ac8c475330611bc3d76a60019b84e937699574d25
BLAKE2b-256 checksum
How to use checksums
786bf36294f57b83611305e807cdd5431a05d43172099b3654b31b3fbdb40d7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 15, 2025.

Transparency log

Release files / pyinitgen-4.0.1-py3-none-any.whl

Download URL pyinitgen-4.0.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d5ef7f213181051ac0276d1aef3e10c398e1cb275293187977b7753f2d72007
BLAKE2b-256 checksum
How to use checksums
18d70567efbce5cea26101eac21ef04193014ff3a5bc7b45c7b8e8d2bbad3ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 15, 2025.

Transparency log

Security for pyinitgen 4.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyinitgen-4.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 15, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page