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)
Links
Project details
Release history Release notifications | RSS feed
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 details)
Built Distribution
File details
Details for the file throttle-0.2.2.tar.gz
.
File metadata
- Download URL: throttle-0.2.2.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c949b0ae118c63e9e1be3e927d7ecdc9c46231248374d4d1cab95123e380e0c |
|
MD5 | 17916282b566bde83d27f92b4bebef8b |
|
BLAKE2b-256 | 935db2ccc39e665ee189eb465c1e637337150e72a65a160dbfcefd0b7b124e94 |
File details
Details for the file throttle-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: throttle-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8bd279e062190708fc1df2bbf0aea5f8460bf7893114ebdb2789ce7a286e9fe |
|
MD5 | 87321a1cc4b2fd208168d852f7d558f9 |
|
BLAKE2b-256 | 66b752f82631b668ec9f0fe28322758d78e75334added5b012362393e5cb7849 |