Giter Club home page Giter Club logo

safepy's Introduction

safepy: safety belt for Python distributed services

https://api.shippable.com/projects/587b8d9379509c10004a444b/badge?branch=master https://api.shippable.com/projects/587b8d9379509c10004a444b/coverageBadge?branch=master

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.

How to use the library

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):
        ...

Retry

from safepy import retry

class ServiceA(object):
    @retry(attempts=3, base_delay=1)
    async def call():
        ...

Notes

  • The default retry is an alias for retry_with_jitter_backoff, a retry mechanism which uses jitter backoff. For exponential backoff use retry_with_exponential_backoff.

safepy's People

Contributors

lowks avatar prokopst avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

lowks

safepy's Issues

Create batching mechanism

The idea is to have a mechanism which would allow transparent batching. So for example:

import asyncio

@batched(max_count=3, interval=0.02)
async def print_numbers(*numbers):
    print(numbers)

async def main():
    await asyncio.gather(
        hello(1), hello(2), hello(3), hello(4), hello(5), hello(6)
    )

asyncio.run_until_complete(main())

Would actually make one call print_numbers per max_count (in random order):

[3, 1, 4]
[2, 6, 5]

Batching is used to produce less http requests:
https://docs.microsoft.com/cs-cz/azure/service-bus-messaging/service-bus-performance-improvements#client-side-batching
or in a situation where it's not feasible to have many items in a queue, so it's better to send the events in a batch.

Create retry mechanism

Create retry mechanism with exponential back-off strategy.

Expected interface:

@retry(attempts=5, exceptions=SomeError, backoff=1)
def function():
    pass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.