fastflowtransform.api.rate_limit¶
TokenBucket
dataclass
¶
Thread-safe token bucket with blocking wait.
Source code in src/fastflowtransform/api/rate_limit.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
wait ¶
wait(cost=1.0)
Block until at least cost tokens are available, then consume them.
Source code in src/fastflowtransform/api/rate_limit.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
try_consume ¶
try_consume(cost=1.0)
Attempt to consume cost tokens without blocking.
Source code in src/fastflowtransform/api/rate_limit.py
45 46 47 48 49 50 51 52 53 54 55 | |
init_rate_limiter ¶
init_rate_limiter(capacity, rps)
Initialize the module-level token bucket. If capacity<=0 or rps<=0, disables the limiter.
Source code in src/fastflowtransform/api/rate_limit.py
69 70 71 72 73 74 75 | |
set_params ¶
set_params(capacity=None, rps=None)
Update parameters. Rebuilds the bucket to apply new settings (keeps behavior simple). If not initialized and both values are provided (and >0), initializes it.
Source code in src/fastflowtransform/api/rate_limit.py
78 79 80 81 82 83 84 85 86 87 88 89 90 | |
rate_limit ¶
rate_limit(cost=1.0)
Block until cost tokens are available. No-op if limiter is disabled/uninitialized.
Source code in src/fastflowtransform/api/rate_limit.py
93 94 95 96 97 98 99 | |
try_consume ¶
try_consume(cost=1.0)
Non-blocking: returns True if tokens were consumed; True as well if disabled/uninitialized.
Source code in src/fastflowtransform/api/rate_limit.py
102 103 104 105 106 107 | |
reset ¶
reset()
Test helper: clear the limiter state (no globals).
Source code in src/fastflowtransform/api/rate_limit.py
110 111 112 | |