Runtime policy engine for Python — .gitignore-style workflow for disabling debug/dev behaviors.
Project description
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.
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 debugignore-0.1.0.tar.gz.
File metadata
- Download URL: debugignore-0.1.0.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d2ba6087cc18b62319ade6c500f12a3e41eee512af8a6aa48b8a3c0ae42776
|
|
| MD5 |
dcc034d5d897f7de0ec7fe2de151a0fd
|
|
| BLAKE2b-256 |
cb96e1b9a1925b441c742f1abe182938a4b85269073a96f7e496464fdfb17050
|
File details
Details for the file debugignore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: debugignore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
415736af627749bab817108e253937414d5c18d2a75ed0fdea2d554bba784ecc
|
|
| MD5 |
1414222bd123c0ef81eba85a3a02166b
|
|
| BLAKE2b-256 |
5599b354aa403512cd5e43c39f941117983c1725df0347feb5a2688368f188b4
|