Skip to main content

License: MIT Build Status

choke is a package implementing a trivial to use general purpose throttling mechanism. The basic workflow with choke is as follows:

  1. Create manager - an object responsible for keeping track of timestamps when some events (think: calls to your functions) occur.

  2. Instruct manager to “choke” some callables, i.e. define maximum number of calls that can occur per given time window.

  3. Use your callables as usual, keeping in mind that when the above defined limit is exceeded, the choked callable will raise CallLimitExceededError.

Here is an example containing everything you need to use choke:

from time import sleep
from redis import StrictRedis
from choke import RedisChokeManager, CallLimitExceededError

REDIS = StrictRedis() # Tweak this to reflect your setup
CHOKE_MANAGER = RedisChokeManager(redis=REDIS)

# Example configuration: enforce limit of no more than 10 calls in two seconds window
@CHOKE_MANAGER.choke(limit=10, window_length=2)
def foo(x, y):
    """Just print something to show that foo was called."""
    print(f'foo called with ({x}, {y})')

if __name__ == '__main__':
    # We expect pattern of 10 successes followed by 10 failures followed again by 10 successes
    # Some deviations from this pattern may obviously occur as calling foo takes nonzero time
    for i in range(30):
        try:
            foo(i, y=i ** 2)
        except CallLimitExceededError:
            print('Foo not called. Limit exceeded!')
        sleep(0.1)

Metadata

Release files for choke 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for choke 0.1.2
File Size Uploaded Provenance
choke-0.1.2.tar.gz 7.1 kB Without provenance Details

Release files / choke-0.1.2.tar.gz

Download URL choke-0.1.2.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
73312fe55de02f838c2b4c2b0f4faae549ef97dbe78efd6e50e5377ac74bf619
BLAKE2b-256 checksum
How to use checksums
10153e465780f8f042a45c636c86efd46288c16a0a5fd6304bf4cfb2c18d98ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Security for choke 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page