errortools¶
errortools is a lightweight Python toolkit for exception handling, warnings, and structured logging. It offers both high-level convenience APIs and zero-overhead helpers for performance-critical code paths.
Something need change or refactor? Contact email errortools.docs@proton.me
At a glance¶
from errortools import ignore, retry, BaseErrorCodes
from errortools.logging import logger
# Suppress exceptions with metadata
with ignore(KeyError) as err:
_ = {}["missing"]
print(err.exception) # KeyError('missing')
# Automatic retry on failure
@retry(times=3, on=ConnectionError, delay=1.0)
def connect(host: str): ...
# Structured exceptions with error codes
raise BaseErrorCodes.not_found("user #42") # NotFoundError [3001]
# Structured logging — no external dependencies
logger.info("Server started on port {}", 8080)
Key features¶
Exception handling. Context managers and decorators for graceful error suppression — see Exception Handling.
Batch raising. Raise one or many exceptions at once with
raises()andraises_all()— see Raising Exceptions.Decorators. Automatic retry (
@retry), async timeout (@timeout), and error-caching (@error_cache) — see Decorators.Custom exceptions. Structured exception classes with error codes, trace IDs, and rich context — see Custom Exceptions.
Future module. Zero-overhead exception handling for hot paths — see Future Module.
Logging. A Loguru-inspired structured logger with no external dependencies — see Logging.
Warnings. A small library of
Warningsubclasses for common deprecation / performance scenarios — see Warnings.Type safety. Full type hints and
typingaliases for IDE-friendly code — see API Reference.
Why errortools?¶
Concern |
Standard library |
errortools |
|---|---|---|
Suppress an exception with metadata |
|
|
Retry on failure |
DIY loop |
|
Structured error code |
subclass |
|
Zero-overhead |
|
|
Structured logging |
|
|
Installation¶
pip install errortools
For development installs and contributing see Installation.
Where to go next¶
Contents
- Getting Started
- User Guide
- API Reference
- Command-Line Interface
- Examples
- Web API Error Handling
- Database Connection with Retry
- Batch Processing with Error Collection
- Configuration Loading with Validation
- Hot Path Optimization
- Structured Logging in Microservices
- Deprecation Management
- Exception Type Conversion
- Error Caching for Expensive Operations
- Multi-Level Error Handling
- Extending errortools
- Frequently Asked Questions (FAQ)
- EMEP (Errortools Module Enhancement Proposal)
- What’s New