Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

benzene-resilience

Resilience policies for Benzene Python beyond the retry that ships in the core — circuit breaker, bulkhead, rate limiting, idempotency, and an in-process saga. Depends only on benzene-core.

pip install benzene-resilience

Every gating policy has one execute(run) seam and ships in two shapes off it — an inbound *_interception middleware and an outbound MessageSender decorator — so it guards a handler pipeline and an outbound client with the same object, composing with the core's with_retry / with_correlation_id.

from benzene.resilience import (
    CircuitBreaker,
    circuit_breaker_interception,
    with_circuit_breaker,
    Bulkhead,
    bulkhead_interception,
    RateLimiter,
    rate_limit_interception,
    InMemoryIdempotencyStore,
    idempotency,
    Saga,
)

# Inbound: cross-cutting middleware, installed ahead of the message router in the AppDefinition.
definition.middleware += [
    rate_limit_interception(
        RateLimiter(refill_rate=100, burst=200)
    ),  # too-many-requests at the edge
    bulkhead_interception(Bulkhead(max_concurrency=20, max_queue=40)),  # shed load past capacity
    idempotency(InMemoryIdempotencyStore(ttl=3600)),  # dedupe redelivered messages
]

# Outbound: decorate a MessageSender, same shape as with_retry.
sender = with_circuit_breaker(orders_client, failure_threshold=5, reset_timeout=30)
  • Circuit breaker — after failure_threshold consecutive server-side failures the circuit opens and rejects with service-unavailable for reset_timeout seconds, then admits one probe; a success closes it, a failure re-opens it. Client errors (bad-request, not-found) are handled outcomes and don't trip it.
  • Bulkhead — at most max_concurrency invocations run at once, max_queue more may wait, and the next is shed immediately with too-many-requests — one slow dependency can't exhaust the service.
  • Rate limiting — a continuous-refill token bucket (refill_rate/sec, tolerating a burst) that enforces too-many-requests at the edge; the concrete producer of that status the port was missing.
  • Idempotency — keys each invocation on an idempotency header and replays the first result for a redelivery, so at-least-once transports don't run a handler twice. Only successes are remembered, so a transient failure stays retryable. The store is a pluggable async port (in-memory impl included).
  • Saga — sequence steps that each know how to undo themselves; a later failure compensates the completed steps in reverse. In-process (not durable) and Result-shaped — execute returns a SagaResult, it never raises for a step failure.

Nothing here needs a broker, a clock you can't control, or any third-party package: the gating policies take an injectable clock, the idempotency store an injectable one too, so every policy is exercised deterministically in memory. Mirrors .NET's Benzene.Resilience.Polly, Benzene.RateLimiting, Benzene.Idempotency, and Benzene.Saga, and contributes the benzene.resilience subpackage to the shared benzene namespace.

Metadata

Release files for benzene-resilience 0.1.0b2

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

Source distribution (sdist)

Source distribution for benzene-resilience 0.1.0b2
File Size Uploaded Provenance Actions
benzene_resilience-0.1.0b2.tar.gz 11.7 kB With provenance Details for benzene_resilience-0.1.0b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for benzene-resilience 0.1.0b2
File Interpreter ABI Platform Actions
benzene_resilience-0.1.0b2-py3-none-any.whl Python 3 none any Details for benzene_resilience-0.1.0b2-py3-none-any.whl

Total release size: 27.7 kB

Release files / benzene_resilience-0.1.0b2.tar.gz

Download URL benzene_resilience-0.1.0b2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8d4482ddd7c49409b48e58824877f7cfcf7d018e5728b0e356ee9ed75e16f798
BLAKE2b-256 checksum
How to use checksums
07c479c8eb075bb6a3d280434509b972c1b2d4ccf8fc5b249350fededf45be79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / benzene_resilience-0.1.0b2-py3-none-any.whl

Download URL benzene_resilience-0.1.0b2-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cfebd4e1a7e749a5737c6db2b3eb325186197c3466c3d84712743ffb6d1bd5f
BLAKE2b-256 checksum
How to use checksums
ceb3cbb38fbc321f40aec8add7fdaf99066a935ad1ece8a9497d333addafc2d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for benzene-resilience 0.1.0b2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for benzene_resilience-0.1.0b2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

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