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.

Download files

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

Source Distribution

benzene_resilience-0.1.0b1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

benzene_resilience-0.1.0b1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file benzene_resilience-0.1.0b1.tar.gz.

File metadata

  • Download URL: benzene_resilience-0.1.0b1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for benzene_resilience-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 dfa01c1d80946ab05958ba7b329540f6fc80456c429abe481bf1a6d8986d12a3
MD5 827f36c16e805bc76a520fef3f0902e1
BLAKE2b-256 bdd0e02ffad16db80690cf57bfa3b9d2d6d8323b50aaec38a4621b17219f0825

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_resilience-0.1.0b1.tar.gz:

Publisher: release.yml on daniellepelley/benzene-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file benzene_resilience-0.1.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for benzene_resilience-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d922679654be88ab6a640c75c9a28862028f8b07b264b76be453c82bfd6886e
MD5 207a1c92e6efdb7ee45987ef2b856ba3
BLAKE2b-256 15b0d8c7d38886b284537192475dc786196f0ab6cc0834adc324dc870c9b0c8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_resilience-0.1.0b1-py3-none-any.whl:

Publisher: release.yml on daniellepelley/benzene-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0b1 This release

2 files

Supported by

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