tranq is a Python library that provides decorator-based, zero-boilerplate error handling with retries, circuit breakers, metrics, and pluggable reporters.

Stars

10

7-day growth

No data

Forks

2

Open issues

0

License

MIT

Last updated

2026-07-27

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It consolidates multiple error-handling patterns (retry with various backoff strategies, circuit breaker, conditional retry, stateful retry) and modern features (sync/async, metrics, profiling, mock error injection) into one consistent API, reducing boilerplate significantly.

Who it is for

  • Python developers building resilient APIs or microservices
  • Engineers who want to replace repetitive try/except blocks with declarative decorators
  • Teams needing circuit breaker patterns for external service calls
  • Testers and developers writing robust error-handling logic who require mock error injection

Use cases

  • Retrying transient network failures in API clients with exponential backoff and jitter
  • Protecting a service from cascading failures using a circuit breaker
  • Batch processing where retry state must persist across multiple invocations
  • Logging and reporting errors to multiple destinations (file, Sentry, Slack) from a single decorator

Strengths

  • Clean decorator and context manager APIs that keep business logic uncluttered
  • Rich retry policies: exponential, linear, Fibonacci backoff, max delay, jitter, and conditional retry on exception or result
  • Built-in sync and async circuit breakers with configurable thresholds and half-open requests
  • Integrated metrics, profiling, and pluggable reporters for observability and testing

Considerations

  • Requires Python 3.9 or newer, excluding older Python versions
  • Relatively new library with a smaller community and ecosystem compared to tenacity or backoff
  • Some advanced features (e.g., stateful retry, custom backoff callbacks) may require deeper understanding of configuration

README quick start

🌿 tranq

Calm error handling for Python – decorator-based, zero boilerplate.


🧘 Why tranq?

Writing repetitive try / except blocks clutters your code and hides the business logic.
tranq gives you declarative error handling with decorators, context managers, and a rich set of retry strategies – so you can focus on what your code does, not how it recovers from failures.

FeatureDescription
🧘 TranquilClean, readable, and maintainable.
🔁 Smart retriesExponential, linear, Fibonacci backoff, jitter, and max delay.
🚦 Circuit BreakerPrevent cascading failures (sync & async).
🧪 Conditional retryOn specific exceptions or result values.
📦 Retry groupsAll-or-nothing execution for multiple functions.
📊 Built‑in metrics & profilingMonitor performance and error rates.
📝 Pluggable reportersSend errors to files, Sentry, Slack, or custom destinations.
🧩 Context manager APIUse tranq.retry(...) when decorators aren't ideal.
🔧 Stateful retryPersist attempt count across calls.
🎭 Mock error injectionTest your error handling with ease.

📦 Installation

pip install tranq

Requires Python 3.9 or later.


⚡ Quick Start

Decorator (@handle)

import tranq

@tranq.handle(on=ValueError, retry=3, delay=0.5, backoff=2.0)
def risky():
    # This will be retried up to 3 times with exponential backoff
    ...

Async (@handle_async)

@tranq.handle_async(on=ConnectionError, retry=2, fallback=lambda: "offline")
async def fetch_data():
    ...

Circuit Breaker

cb = tranq.CircuitBreaker(failure_threshold=5, timeout=60)

@tranq.handle(circuit_breaker=cb)
def call_unstable_service():
    ...

Context Manager

with tranq.retry(on=ValueError, retry=2) as ctx:
    result = ctx.run(my_function, arg1, arg2)

Retry Group (all‑or‑nothing)

group = tranq.retry_group(step1, step2, step3, on=Exception, retry=1)
results = group.run()  # if any step fails, all are retried together

🔍 Features in Depth

1. Retry with Backoff

Choose from exponential, linear, or Fibonacci backoff. Add jitter to avoid thundering herds.

@tranq.handle(
    on=TimeoutError,
    ret

Description

Calm error handling for Python

Related repositories

Similar projects matched by category, topics, and programming language.

vercel-labs
Featured
vercel-labs GitHub avatar

scriptc

scriptc compiles ordinary TypeScript into small, fast native executables without needing Node.js, V8, or any JavaScript runtime in the binary.

Developer ToolsCode Quality & Build
1,985
programmersd21
Featured
programmersd21 GitHub avatar

flow

flow is a minimalist terminal dashboard that displays real-time network throughput with smooth animations, multiple responsive modes, and zero configuration.

Developer ToolsCLI & Terminal
277
jamesob
Featured
jamesob GitHub avatar

local-llm

A comprehensive guide for building and configuring a high-end local machine to run state-of-the-art LLMs, with detailed hardware choices, BIOS tuning, and Docker-based model serving.

AI & Machine LearningLarge Language Models
1,660