Skip to main content

A more efficient way of conforming to limits via waiting

Project description

waiter.py

PyPI PyPI - Downloads

A more efficient way of conforming to limits via waiting


Think of waiter as Python's built-in sleep() function but instead of sleeping every time it is called, it will only sleep if it needs to. This makes it easier to conform to known rate limits while avoiding unnecessary sleeps.

Let's assume you are consuming a REST API that has a rate limit of 2 requests per second. Naturally you could simply sleep for 500ms after each request as to not hit this limit. However what if you make one request, sleep for 500ms, do something else that takes longer than 500ms, make another request, and then sleep once more for 500ms? The last sleep would be unnecessary.

waiter lets you create functions that will only sleep when needed:

from waiter import create_waiter

wait = create_waiter(500)

make_quick_request()  # takes 10ms
wait()  # sleeps for 490ms
make_slow_request()  # takes 1000ms
wait()  # does not sleep

You can also decorate functions:

from waiter.decorator import will_wait

@will_wait(500)
def my_func():
    #  ...

#  You know the drill

Project details


Download files

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

Source Distribution

waiter.py-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

waiter.py-1.0.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file waiter.py-1.0.0.tar.gz.

File metadata

  • Download URL: waiter.py-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for waiter.py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b70c8161c7d35054bf5891a016a92bb96aee79cf9192f6e167bb972ca1eec66
MD5 5b23e15bc8f2d7693a41bb647a06023e
BLAKE2b-256 f6a5a8b377c490b7891dca913bf11c8598c80070b92902aa16910c99624bdbb2

See more details on using hashes here.

File details

Details for the file waiter.py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: waiter.py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for waiter.py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2148de5850fa73ab13530cff9573511953e9289fc88ec8bef3f961f92a97c868
MD5 b480d69a2655fbd400dfcdc9640cd87e
BLAKE2b-256 24addfe2bc812efc3c7489e09a21999dc92b36d5b30322520fc9401a3fe234e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page