This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Thread-safe (or async-safe) rate limiter for Python | |
| # | |
| # Very simple but effective: no buckets, tokens, queues, or sleep | |
| # Allows for both smooth limiting and windowed bursts | |
| # Intended for a single client (not distributed) with no long-term memory | |
| import threading | |
| from functools import wraps | |
| from threading import Thread, Timer | |
| from typing import Callable, ParamSpec, TypeVar |