Skip to main content

A simple throttling controller

Project description

throttle-controller

Python PyPI version shields.io License codecov

Motivation

This package provides a simple throttle controller for general use-cases. For example, you can use this package to throttle API requests to avoid rate-limiting.

Usage

from throttle_controller import SimpleThrottleController

throttle = SimpleThrottleController.create(default_cooldown_time=3.0)
throttle.wait_if_needed("http://example.com/path/to/api")
throttle.record_use_time_as_now("http://example.com/path/to/api")
... # requests
throttle.wait_if_needed("http://example.com/path/to/api")  # wait 3.0 seconds
throttle.record_use_time_as_now("http://example.com/path/to/api")

with statement

from throttle_controller import SimpleThrottleController
throttle = SimpleThrottleController.create(default_cooldown_time=3.0)

for _ in range(10):
    with throttle.use("http://example.com/path/to/api"):
        # wait if cooldown needed
        requests.get("http://example.com/path/to/api")

Caution

Currently this package supports only to use in single thread / single process use-cases.

LICENSE

The 3-Clause BSD License. See also LICENSE file.

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_controller-0.3.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

throttle_controller-0.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file throttle_controller-0.3.0.tar.gz.

File metadata

  • Download URL: throttle_controller-0.3.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for throttle_controller-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2564e96f2b99ce3bf8e22baf441b9dac66a002eb5b719174b11fc0dee52bf09b
MD5 33e17e0ce7209d505565d943ed644acc
BLAKE2b-256 5bc69e9b76e425fdf0512bcbbc4deaa6372840fd1ec6f81f2635ea7b89c66430

See more details on using hashes here.

File details

Details for the file throttle_controller-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for throttle_controller-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6a425cfa77518183f90f959a2396e7a11f0d6d61e0f8ec7e31171c9ede3c1e0
MD5 c899ad96454169bc62f92b5c02581299
BLAKE2b-256 0a3b482650fe9fdcaf47093dbbcf0b1403371e2d6827e15377e508d67971eedc

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