errortools
A lightweight Python exception handling utility library.
Overview
errortools provides a comprehensive toolkit for working with Python exceptions, warnings, and logging. It offers both high-level convenience functions and low-overhead utilities for performance-critical code.
Key Features
Exception Handling: Context managers and decorators for graceful error suppression
Batch Operations: Raise multiple exceptions at once with
raises_all()andExceptionGroupRetry & Timeout: Automatic retry logic and async timeout decorators
Custom Exceptions: Structured exception classes with error codes, trace IDs, and context
Future Module: Zero-overhead exception handling for hot paths
Logging: Loguru-inspired structured logger with no external dependencies
Type Safety: Full type hints and type aliases for better IDE support
Quick Example
from errortools import ignore, retry, BaseErrorCodes
from errortools.logging import logger
# Suppress exceptions with metadata
with ignore(KeyError) as err:
_ = {}["missing"]
print(err.be_ignore) # True
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
logger.info("Server started on port {}", 8080)
Installation
pip install errortools
Documentation Structure
Contents
- Installation
- Quick Start
- Core Features
- Exception Handling
- Raising Exceptions
- Decorators
- Custom Exceptions
- Warnings
- Future Module
- Logging
- Plugin System
- Command-Line Interface
- API Reference
- 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
- Erron the great