Skip to main content

Frequency tracking and throttling utilities.

Project description

pip3 install throttle

Simple Usage

import time
import throttle

# limit to 3 calls
# allow more every 1 second
@throttle.wrap(1, 3)
def aesthetic(*values):

  return ' '.join(values).upper()

for index in range(10):

  result = aesthetic('beautiful')

  success = not result is throttle.fail

  print(index, success)

  time.sleep(0.23)

Complex Usage

import time
import random
import throttle

# allow more every 1 second
delay = 1

# limit to 3 calls
limit = 3

# only check values less than 5 against the limit
key = lambda value: value < 5

# or Static()
valve = throttle.Valve()

# make some quick calls
for index in range(30):

  item = random.randrange(0, 8)

  allow = valve.check(delay, limit, item, key = key)

  print(item, allow)

  time.sleep(0.23)

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

throttle-0.2.2.tar.gz (4.0 kB view hashes)

Uploaded source

Built Distribution

throttle-0.2.2-py3-none-any.whl (5.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page