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.1.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

throttle_controller-0.3.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: throttle_controller-0.3.1.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for throttle_controller-0.3.1.tar.gz
Algorithm Hash digest
SHA256 2b0f19ea3d42d26af5518cd69d2d41d2ed82d1aed5ff80128d5e580d717bc1e2
MD5 16a3f26f8e7327e0dbe7dc31406fc6ae
BLAKE2b-256 187d741afb3ed199e4e6230c4c5368b13a8143a06cedaa46df82beaf407531bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for throttle_controller-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 621d32b3cceb6b839539dbd8a8e2f7dd9226f664c2754f8bdfb2030b9100f802
MD5 6fb281ec767157240aa8cf78d3321e5c
BLAKE2b-256 8cb20a661ce3b4122a1ea0ceabcb6d866da4c88f471103159294d5061d1df311

See more details on using hashes here.

Supported by

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