A robust error handling and exception management library for Python. PyError provides utilities for logging and raising exceptions with flexible exception types, error codes, and custom parameters.
- Flexible Exception Handling: Support for custom exceptions with configurable error codes and additional parameters.
- Logging Integration: Integrated logging via
flashloggerfor fatal, critical, and error levels. - Positional and Keyword Arguments: Support for passing additional arguments (
*args) and keyword arguments (**kwargs) to exceptions. - Multiple Exception Types: Functions for fatal, critical, and error scenarios with consistent interfaces.
- Easy Extension: Extensible design allowing custom exception classes with complex initialization logic.
Install from PyPI:
pip install PyErrorOr clone the repository and install locally:
git clone https://github.com/kingkybel/PyError.git
cd PyError
pip install .from error import fatal
# Raise a fatal error with default SystemExit
fatal("Critical system failure")
# Raise a fatal error with custom error code
fatal("Database connection failed", error_code=2)
# Raise a custom exception
class DatabaseError(Exception):
def __init__(self, code, *args, **kwargs):
self.code = code
super().__init__(*args, **kwargs)
fatal("Connection timeout", exception=DatabaseError, error_code=42)from error import critical
# Raise a critical error
critical("Authentication failed")
# With custom exception
critical("Invalid configuration", exception=ConfigError, error_code=10)from error import error
# Raise an error
error("File not found")
# With additional parameters
error("Operation failed", exception=OperationError, error_code=1)from error import fatal
class AppError(Exception):
def __init__(self, code, *args, **kwargs):
self.code = code
self.context = kwargs.get('context')
self.timestamp = kwargs.get('timestamp')
# Pass extra keyword arguments
fatal("App failed", AppError, 5, context="user_login", timestamp="2026-05-04")Run the test suite:
python -m unittest PyError.test.test_errorOr with verbose output:
python -m unittest PyError.test.test_error -vkingkybel-pyfundamentalskingkybel-pyflashlogger
See LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.