Safepy (rhymes with safety) is a latency and fault tolerance library for Python 3.5 (or greater) inspired by Hystrix, Cloud Design Patterns, AWS Architecture Blog and many others.
You can either use the mechanisms as decorators:
from safety import retry
class ProfileService(object):
@retry(attempts=3, base_delay=1)
async def get_profile(self, username):
...
Or to dynamically recreate protected methods:
from safety import retry
class ProfileService(object):
def __init__(self):
self.get_profile = retry(attempts=3, base_delay=1)(
self.get_profile
)
async def get_profile(self, username):
...
from safepy import retry
class ServiceA(object):
@retry(attempts=3, base_delay=1)
async def call():
...
- The default
retry
is an alias forretry_with_jitter_backoff
, a retry mechanism which uses jitter backoff. For exponential backoff useretry_with_exponential_backoff
.