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

Uploaded Source

Built Distribution

throttle_controller-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file throttle-controller-0.2.0.tar.gz.

File metadata

  • Download URL: throttle-controller-0.2.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for throttle-controller-0.2.0.tar.gz
Algorithm Hash digest
SHA256 95904c8ed09eb9f6df3089d7cd33a6c1d36b2ed30ed21001165366b2bd1b23b8
MD5 598448cc2510cdffe972be77f9e9840c
BLAKE2b-256 de7e6167f904bd3550c5247f066489d4595f7a16e58182c257e799af8206845f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for throttle_controller-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac2f4b111219032dc60ad7d2b37557f727967850e0800d90568df6662376ed1
MD5 f7b588f41f120b7e47492fcdbd98dbb1
BLAKE2b-256 055f071919b661326e7c73818fb009d4eadfd9e1204ac5c7d5b7456cdcb4da52

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