Opero: resilience and parallelism for Python functions
Two decorators — @opero and @opmap — add automatic retries, parameter fallbacks, caching, rate limiting, and parallel execution to any Python function with minimal code changes.
Install
pip install opero
# Optional extras
pip install opero[pathos] # multiprocessing with complex objects
pip install opero[aiomultiprocess] # async multiprocessing
pip install opero[all] # everything
Quick example
from opero import opero, opmap, AllFailedError
# Single-call resilience: cache results, retry up to 3 times,
# fall back through a list of API keys on failure.
@opero(cache=True, cache_ttl=3600, retries=3, arg_fallback="api_key", rate_limit=5.0)
async def fetch(item_id: str, api_key: str = None):
# api_key receives one value from the caller-supplied list on each attempt
return await call_api(item_id, api_key)
# Pass the list explicitly; the decorator tries each key until one succeeds.
result = await fetch("item-123", api_key=["key1", "key2", "key3"])
# Batch resilience: same protections, applied in parallel across many items.
@opmap(mode="thread", workers=8, retries=2)
def process(item: dict):
return transform(item)
results = process(list_of_items) # returns list; failed items are exceptions
What each mechanism does
Retries (retries, backoff_factor, min_delay, max_delay, retry_on)
Re-runs the function on failure using exponential backoff with jitter (via tenacity). Set retry_on to restrict which exception types trigger a retry.
Parameter fallbacks (arg_fallback)
Names a parameter that receives one value at a time from a caller-supplied list. Pass the list explicitly at call time; on each failure the decorator retries with the next item. Useful for rotating API keys, backup endpoints, or config profiles. Raises AllFailedError when the list is exhausted.
Caching (cache, cache_ttl, cache_backend, cache_namespace, cache_key)
Skips the function body on repeated calls with the same arguments (via twat-cache). Backends: "memory" (default), "disk", "redis".
Rate limiting (rate_limit)
Caps calls-per-second using asynciolimiter. Protects downstream APIs from being hammered.
Parallel execution (mode, workers, ordered, progress) — @opmap only
Maps the decorated function across a list of inputs using twat-mp. Modes:
| Mode | Best for |
|---|---|
"thread" |
I/O-bound work (HTTP, DB, file) |
"process" |
CPU-bound work |
"async" |
Async I/O functions |
"async_process" |
Async functions in separate processes |
Failed items are returned as exception objects in the results list rather than stopping the batch.
Execution order
Each call goes through: cache check → rate limiter → retry loop → fallback cycle.
Error handling
from opero import AllFailedError
try:
result = await fetch("item-42")
except AllFailedError as e:
for i, err in enumerate(e.errors):
print(f"attempt {i + 1}: {err}")
Async support
Both sync and async functions work. Opero detects async functions automatically and uses async-compatible retry and rate-limit implementations.
Logging
from opero import configure_logging
import logging
configure_logging(level=logging.DEBUG) # see retries, cache hits, fallbacks
Package structure
| Module | Purpose |
|---|---|
decorators/opero.py |
@opero — single-call resilience decorator |
decorators/opmap.py |
@opmap — batch parallel resilience decorator |
core/retry.py |
Exponential backoff retry via tenacity |
core/fallback.py |
Parameter-list fallback cycling |
core/cache.py |
Cache integration via twat-cache |
core/rate_limit.py |
Rate limiting via asynciolimiter |
concurrency/pool.py |
Parallel executor via twat-mp |
exceptions.py |
OperoError, AllFailedError |
Development
git clone https://github.com/twardoch/opero && cd opero
pip install hatch
hatch shell
hatch run test # run tests
hatch run lint:all # ruff + mypy
License
MIT.
Metadata
Release files for opero 2.7.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opero-2.7.8.tar.gz | 1.5 MB | With provenance | Details for opero-2.7.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opero-2.7.8-py3-none-any.whl | Python 3 | none | any | Details for opero-2.7.8-py3-none-any.whl |
Total release size: 1.5 MB
Release files / opero-2.7.8.tar.gz
| Download URL | opero-2.7.8.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
646139161b5c20d1137b1c6b7943f850ad569757f738c212c4e828a8ef645087
|
|
BLAKE2b-256 checksum How to use checksums |
94e59ae18755a6f863ed09683a0ae145eaba4fd8346c288717d74cd700031247
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 17, 2026.
Transparency logRelease files / opero-2.7.8-py3-none-any.whl
| Download URL | opero-2.7.8-py3-none-any.whl |
|---|---|
| Size | 28.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ae704207a951a8f01010a3f33c9cb5898c50002e196e0980f6dcd7165c2ffbd
|
|
BLAKE2b-256 checksum How to use checksums |
15e38edf4589207c8e06a3b66658078604564d3f1fd69b2ef841cd62c50c337b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 17, 2026.
Transparency logSecurity for opero 2.7.8
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
Both files in this release have been uploaded with provenance metadata.
Attestation for opero-2.7.8.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 Nov 17, 2026.
Transparency logA 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.