Skip to main content

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

Metadata

Release files for errortools 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for errortools 4.0.0
File Size Uploaded Provenance
errortools-4.0.0.tar.gz 121.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for errortools 4.0.0
File Interpreter ABI Platform
errortools-4.0.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details

Total release size: 286.4 kB

Release files / errortools-4.0.0.tar.gz

Download URL errortools-4.0.0.tar.gz
Size 121.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8739c3c2bb88f3bcfa73039bc00d383a42b42e45ef7de77977d560d4821adbd
BLAKE2b-256 checksum
How to use checksums
6974073bbcedf14bb29e8e6096a291e7361c899c6051558ec293cec80a84726e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / errortools-4.0.0-cp314-cp314-win_amd64.whl

Download URL errortools-4.0.0-cp314-cp314-win_amd64.whl
Size 164.8 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
7ca7db52b5a7caa5212f610de685117c620f7edbfb84e8307d6430d020aee1e6
BLAKE2b-256 checksum
How to use checksums
1721767da137932b197e46848cb14572da2b7f0581056260f8b4389622c9c1bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for errortools 4.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page