One import. Zero code changes. Full runtime control.
debugignore brings a .gitignore-style workflow to Python runtime behaviors. It lets you dynamically disable prints, debug logs, network requests, or file writes directly from a configuration file, without modifying your source code.
📖 Table of Contents
- The Problem Statement
- Why not just use standard logging?
- ✨ Key Features
- 🚀 Installation
- ⚡ Quick Start
- 🛠 Rule Syntax & Usage
- 🏗 Architecture Overview
- 🗺 Roadmap
- 🤝 Contributing
- 📄 License
🎯 The Problem Statement
During development, we heavily rely on print(), logging.debug(), helper decorators, and mock network calls to iterate quickly. However, stripping these out before a production release is tedious, error-prone, and often results in noisy logs or accidental data leaks.
debugignore solves this by safely monkey-patching specified targets at runtime, turning them into safe noop operations based on a centralized .debugignore file.
🤔 Why not just use standard logging?
While Python's standard logging library is robust, it doesn't cover everything:
- You can't easily suppress third-party module network calls (like an accidental
requests.post()in a test environment). - Junior developers often leave
print()statements behind. - You might want to temporarily disable file writes (
open(..., "w")) during dry-run executions without wrapping your entire I/O layer in conditionals.
debugignore acts as an enforcer, working seamlessly alongside your existing logging framework.
✨ Key Features
- Zero Boilerplate: Only requires
import debugignore. .gitignoreSyntax: Familiar wildcard and glob matching for rules.- Environment Aware: Mode-scoped rules (e.g.,
[production] print). - Safe Patching: Original callables are preserved and can be restored at any time.
- Lazy Hooking: Hooks into
sys.meta_pathto intercept modules imported afterdebugignore. - Pure Python: No C-extensions, no third-party dependencies.
🚀 Installation
Install via pip:
pip install debugignore
For development and testing:
pip install debugignore[dev]
⚡ Quick Start
1. Create a .debugignore file
Place this in the root of your project:
# Suppress all built-in prints
print
# Block all outgoing HTTP posts via requests
requests.post
# Silence standard debug logging
logging.debug
2. Import it once
Import it as early as possible in your application lifecycle (e.g., in main.py or __init__.py).
import debugignore
import requests
import logging
print("This will NOT appear.")
requests.post("https://api.example.com/webhook", json={"test": True}) # Blocked safely
logging.debug("This is silenced.")
🛠 Rule Syntax & Usage
| Pattern | Effect |
|---|---|
print |
Suppress builtins.print |
json.dumps |
Suppress a specific module attribute |
json.* |
Suppress all public callables in json |
debug_* |
Suppress any callable matching the glob |
requests.post |
Safely block requests.post() |
open |
Intercept file writes (reads still work) |
*.write |
Intercept file writes via any matched write method |
stdout / stderr |
Redirect streams to /dev/null equivalent |
app.py:120 |
Suppress calls originating from a specific file:line (best-effort) |
[production] print |
Only suppress print when DEBUGIGNORE_MODE=production |
Environment Variables
DEBUGIGNORE_MODE=production— Activates rules tagged with[production].DEBUGIGNORE=1— Forces engine activation even if the.debugignorefile is missing.
API Reference
If you prefer manual control over auto-activation:
import debugignore
debugignore.enable() # Activate manually
debugignore.disable() # Restore all original functions
debugignore.reload() # Re-read .debugignore and apply
You can also use the context manager for temporary suppression:
with debugignore.disabled():
print("This WILL print, even if blocked globally.")
🏗 Architecture Overview
debugignore is built on a non-destructive patching engine:
- Parser: Reads
.debugignoreand constructs strongly-typedRuleinstances. - Patterns Engine: Uses
fnmatchto match rules against runtime targets. - Patcher: Applies monkey-patches. It heavily relies on
debugignore.utils.noopto ensure return types don't crash standard operations. - Hooks: Installs a
sys.meta_pathfinder to intercept and patch modules that are imported afterdebugignoreis initialized.
🗺 Roadmap
Future plans for debugignore include:
- Async Support: Wrapping
async deftargets with awaitable noops. - CLI Analyzer:
debugignore checkto dry-run rules against a codebase using AST analysis. - FastAPI / Django Plugins: First-class middleware for web frameworks.
- Policy Validation: Strict mode to raise exceptions instead of silent suppression (useful in CI).
🤝 Contributing
Contributions are highly welcome! We use pytest for tests and mypy for static analysis.
Please read our Contributing Guide for full instructions on setting up your environment and submitting Pull Requests.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for debugignore 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| debugignore-0.1.0.tar.gz | 1.5 MB | Without provenance | Details for debugignore-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| debugignore-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for debugignore-0.1.0-py3-none-any.whl |
Total release size: 1.5 MB
Release files / debugignore-0.1.0.tar.gz
| Download URL | debugignore-0.1.0.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92d2ba6087cc18b62319ade6c500f12a3e41eee512af8a6aa48b8a3c0ae42776
|
|
BLAKE2b-256 checksum How to use checksums |
cb96e1b9a1925b441c742f1abe182938a4b85269073a96f7e496464fdfb17050
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / debugignore-0.1.0-py3-none-any.whl
| Download URL | debugignore-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
415736af627749bab817108e253937414d5c18d2a75ed0fdea2d554bba784ecc
|
|
BLAKE2b-256 checksum How to use checksums |
5599b354aa403512cd5e43c39f941117983c1725df0347feb5a2688368f188b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for debugignore 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.