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_thresholdconsecutive server-side failures the circuit opens and rejects withservice-unavailableforreset_timeoutseconds, 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_concurrencyinvocations run at once,max_queuemore may wait, and the next is shed immediately withtoo-many-requests— one slow dependency can't exhaust the service. - Rate limiting — a continuous-refill token bucket (
refill_rate/sec, tolerating aburst) that enforcestoo-many-requestsat 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 —executereturns aSagaResult, 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfa01c1d80946ab05958ba7b329540f6fc80456c429abe481bf1a6d8986d12a3
|
|
| MD5 |
827f36c16e805bc76a520fef3f0902e1
|
|
| BLAKE2b-256 |
bdd0e02ffad16db80690cf57bfa3b9d2d6d8323b50aaec38a4621b17219f0825
|
Provenance
The following attestation bundles were made for benzene_resilience-0.1.0b1.tar.gz:
Publisher:
release.yml on daniellepelley/benzene-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benzene_resilience-0.1.0b1.tar.gz -
Subject digest:
dfa01c1d80946ab05958ba7b329540f6fc80456c429abe481bf1a6d8986d12a3 - Sigstore transparency entry: 2467247539
- Sigstore integration time:
-
Permalink:
daniellepelley/benzene-python@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/daniellepelley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file benzene_resilience-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: benzene_resilience-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d922679654be88ab6a640c75c9a28862028f8b07b264b76be453c82bfd6886e
|
|
| MD5 |
207a1c92e6efdb7ee45987ef2b856ba3
|
|
| BLAKE2b-256 |
15b0d8c7d38886b284537192475dc786196f0ab6cc0834adc324dc870c9b0c8b
|
Provenance
The following attestation bundles were made for benzene_resilience-0.1.0b1-py3-none-any.whl:
Publisher:
release.yml on daniellepelley/benzene-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benzene_resilience-0.1.0b1-py3-none-any.whl -
Subject digest:
6d922679654be88ab6a640c75c9a28862028f8b07b264b76be453c82bfd6886e - Sigstore transparency entry: 2467241986
- Sigstore integration time:
-
Permalink:
daniellepelley/benzene-python@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/daniellepelley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Trigger Event:
workflow_dispatch
-
Statement type: