Skip to main content

errortools - a toolset for working with Python exceptions and warnings and logging.

Project description

errortools

A lightweight Python exception handling utility library.

Code Style: Google PyPI Version Python Versions This week commits This month commits Past year commits Total commits badge OS support

Something need change or refactor? Contact email errortools.docs@proton.me

Installation

Use pip...

pip install errortools

...or uv

uv add errortools

Features

  • Suppress: ignore(), super_fast_ignore(), @suppress() — silence exceptions gracefully
  • Retry & Timeout: @retry(), @timeout() — auto retry with delay, async timeout
  • Raise & Convert: raises(), reraise(), @convert() — batch raise, type conversion
  • Catch & Collect: super_fast_catch(), ExceptionCollector — inspect or batch exceptions
  • Caching: @error_cache — LRU exception cache, like functools.lru_cache
  • Custom Exceptions: PureBaseException, ContextException, BaseErrorCodes
  • Logging: structured logger with sinks, context binding, and exception capture

Quick Start

from errortools import ignore, retry, reraise, error_cache, suppress, convert
from errortools.future import super_fast_ignore, super_fast_catch, ExceptionCollector

# ── Suppress ─────────────────────────────────────────────────
with ignore(KeyError) as err:               # full metadata
    _ = {}["missing"]
# err.be_ignore=True, err.name='KeyError', err.traceback=...

with super_fast_ignore(ValueError):         # zero-overhead
    int("bad")

@suppress(ZeroDivisionError, default=0)     # decorator form
def divide(a, b): return a / b

# ── Retry ────────────────────────────────────────────────────
@retry(times=3, on=ConnectionError, delay=1.0)
def connect(host: str): ...

# ── Convert ──────────────────────────────────────────────────
@convert(KeyError, ValueError)              # decorator
def lookup(d, key): return d[key]

with reraise(KeyError, ValueError):         # context manager
    raise KeyError("x")                     # → ValueError

# ── Catch & Collect ──────────────────────────────────────────
with super_fast_catch(ValueError) as ctx:
    raise ValueError("oops")
# ctx.exception → ValueError('oops')

collector = ExceptionCollector()
collector.catch(int, "bad1")
collector.catch(int, "bad2")
collector.raise_all()                       # → ExceptionGroup

# ── Cache ────────────────────────────────────────────────────
@error_cache(maxsize=64)
def load(uid: int):
    if uid < 0: raise ValueError(f"invalid: {uid}")
    return {"id": uid}

Custom Exceptions

from errortools import PureBaseException, ContextException, BaseErrorCodes

class AppError(PureBaseException):
    code = 9000
    default_detail = "Application error."

err = ContextException("failed").with_context(service="db")
raise BaseErrorCodes.not_found("user #42")  # NotFoundError [3001]

Logging

from errortools.logging import logger

logger.info("Server started on port {}", 8080)
logger.add("app.log", rotation=10_485_760, retention=5)
with logger.catch():
    int("not a number")                     # logged + suppressed

Documentation

Full docs: docs | License: LICENSE

Email

Main email: errortools@proton.me Support email: errortools-support@proton.me Security email: errortools-security@proton.me Agents contact email: errortools.agent-preview@proton.me

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

errortools-3.6.0.tar.gz (65.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

errortools-3.6.0-cp314-cp314-win_amd64.whl (85.8 kB view details)

Uploaded CPython 3.14Windows x86-64

File details

Details for the file errortools-3.6.0.tar.gz.

File metadata

  • Download URL: errortools-3.6.0.tar.gz
  • Upload date:
  • Size: 65.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for errortools-3.6.0.tar.gz
Algorithm Hash digest
SHA256 9c08dd1898f79cbe39a00ddc155c851909faf3e2ce5259e3b35accc915e0b9a4
MD5 b98ccf447ecc71404c66e3c45d208b30
BLAKE2b-256 1f73b0c80fc12a5c383334d51e30649e2e4a551fed121724ebef73f3bdf98ed8

See more details on using hashes here.

File details

Details for the file errortools-3.6.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: errortools-3.6.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 85.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for errortools-3.6.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 80af46acf14d831bae94e20cea7716ea7a07674db572eecae1eb98a45b921b9c
MD5 afcc086486f59a7561b1c0b0f703c037
BLAKE2b-256 248611aab3ee487cb44e0eb5b9f6b503fa392355a64c06b6db59eccae1ce1f4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page