Repository navigation
fix(deps): update dependency pyrate-limiter to v4 - #2144
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
renovate
Bot
force-pushed
the
renovate/pyrate-limiter-4.x
branch
2 times, most recently
from
November 21, 2026 06:14
6f6c9e6 to
51ceb5a
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
>= 3, < 4→>=3, <5Release Notes
vutran1710/PyrateLimiter (pyrate-limiter)
v4.5.1Compare Source
Bug fixes only. One behaviour change to note: a decorated call that the limiter
can never admit now raises instead of running (see the first entry).
Fixed
as_decoratorran the wrapped function even when denied. Both the syncand async wrappers discarded the result of
try_acquire()and called thefunction unconditionally. With the default
blocking=True, timeout=-1thatresult is only
Falsewhen the weight can never be admitted under theconfigured rates (e.g.
weight=5onRate(2, Duration.SECOND)), so thelimiter's verdict was silently bypassed. Such calls now raise
RuntimeError.Limiter.close()never closed its buckets.BucketFactory.close()readthe bucket list off the leaker after tearing the leaker down, so it always
iterated an empty list: SQLite connections and Postgres connection pools
stayed open. It now snapshots the buckets first.
SingleBucketFactoryalsocloses its bucket when no leak was ever scheduled; factories that hold buckets
outside the leaker can extend the new
BucketFactory.owned_buckets().StateBucketwaits.BucketAsyncWrapper.waiting()called the generic log-bucket implementation instead of the wrapped bucket's,
so GCRA /
TokenBucketwaits came back as-1or0. An admissible requestcould be rejected outright, or a blocking limiter could retry without waiting.
retry loop advanced the item's timestamp by the requested delay only. A late
wake-up therefore recorded the acquisition in the past and let later requests
through early. The timestamp is now re-read from the bucket factory's clock,
and the deadline is enforced around the whole retry loop.
keyed by a CRC-32 of the table name rather than
hash(), which Python saltsper interpreter. Processes sharing a database took different locks, so their
concurrent
CREATE TABLE IF NOT EXISTScould fail withUniqueViolationonpg_type_typname_nsp_index.PostgresBucket.peekread timestamps as UTC. Theitem_timestampcolumnis a
TIMESTAMPthatTO_TIMESTAMPfills through the session time zone, butpeektook its epoch as if it were UTC. Outside UTC every peeked item sat thezone's offset in the future, so a full bucket computed a wait of that many
hours and blocking callers slept through it.
peeknow casts the column backthrough the session zone.
v4.5.0Compare Source
Pluggable rate-limiting algorithms. Additive — no breaking public API changes;
the default behaviour of every existing bucket is unchanged.
Added
GCRA/TokenBucketalgorithms, andStateBucketto run them. Thesekeep a couple of numbers per key instead of one entry per consumed unit, so
storage does not grow with traffic and the wait is exact without any lookup.
TokenBucketisGCRAunder a familiar name — one implementation, not two.Stores:
InMemoryStateStore,MultiprocessStateStore, andRedisStateStore(transition runs as a Lua script, so the read-modify-write is atomic across
clients; keys carry a TTL and need no
leak()). For a 1000/minute limit atsaturation the Redis state is ~100 bytes against roughly 89 KB of sorted set.
GCRA's state is integer microseconds rather than fractional milliseconds:
accumulating a fractional emission interval onto an absolute timestamp loses
the low bits, which would reject the last unit of a full burst.
Rate(..., burst=N)— how many units may be spent at once. Read only bythe constant-state algorithms; defaults to
limit, which is classictoken-bucket behaviour.
burst=1is a perfectly smooth drip.WallClock— epoch-millisecond clock, for state compared across machineswhere a monotonic clock is meaningless.
RedisStateStoredefaults to it.limiter_factory.create_token_bucket_limiter().FixedWindowalgorithm. Counts within a wall-clock-aligned window thatresets every
interval, rather than a rolling one. Pass it to any built-inbucket:
InMemoryBucket(rates, algorithm=FixedWindow()). Cheaper and coarserthan the default — up to
2 * limitcan pass across a boundary — and theright choice for mirroring an upstream API that genuinely resets on the hour.
Works on all five backends.
Every built-in bucket now takes an
algorithm=argument, defaulting toSlidingWindowLog(). Existing code is unaffected.Decisionnow carriesretry_after_msalongside the verdict, andput()records it.
AbstractBucket.waiting()reads that recording instead ofderiving the wait from storage a second time. Custom buckets that record
nothing keep working:
waiting()falls back to the previouspeek()-basedderivation.
AbstractBucket.put_decision()returns the fullDecisionfor a put, so theverdict and the retry-after arrive together rather than via the
failing_rateattribute plus a follow-upwaiting()call.Algorithm,LogAlgorithm,DecisionandSlidingWindowLogare exportedfrom the package root.
Fixed
pip install "pyrate-limiter[all]"— the command the README has alwaysdocumented — previously resolved to nothing: the project declared only PEP 735
[dependency-groups], which pip cannot reach through extras syntax, so theinstall emitted
WARNING: does not provide the extra 'all'and then failed atimport redis.redis,postgres,filelockandallnow all work.put()now clearsfailing_rate. Every otherbackend already did; SQLite left the last denial standing indefinitely.
Performance
verdict, so a rate-limited request no longer needs a second
ZRANGEroundtrip to learn how long to wait — and the wait can no longer be computed
against a sorted set that moved in between.
EXCLUSIVEtable lock as the check, removing both a round trip and that same race.
put()'s existing lock hold, sothe background
Leakercannot delete rows between the verdict and the wait.put()already performs — no second scan, and no allocation on the admit path.Documentation
implementing "the Leaky-Bucket algorithm". The default has always been a
sliding-window log; the leaky-bucket meter is now genuinely available as
GCRA, so the term is reserved for it.Internal / Refactor
StateAlgorithmdeclaresredis_args(rates)so a policy's Lua script and itsarguments stay a matched pair it owns.
RedisStateStorepasses them throughwithout inspecting them, rather than assuming GCRA's shape.
Algorithm.max_weight(rate)is the one place asking whether a weight can everbe admitted —
rate.limitfor the window algorithms,rate.burstfor GCRA.Algorithmnow has two sub-interfaces:LogAlgorithm(an entry per consumedunit) and
StateAlgorithm(a fixed tuple of numbers).StateAlgorithm.step()must evaluate every rate before committing any of them, so a rate failing late
never leaves an earlier one debited.
LogAlgorithmout ofAlgorithmfor policies whose state is a log oftimestamped items.
leak_bound()and the newblocking_offset()/retry_after()hooks live there; constant-state policies (token bucket, GCRA)will not implement it.
+1boundary correction now lives in exactly one place(
SlidingWindowLog.retry_after) instead of being inlined inwaiting().v4.4.0Compare Source
Bug-fix, scalability, and internal-refactor release. No public API changes
(the new
AbstractBucket.is_asyncattribute is additive).Fixed
background
Leakerthread can no longer raceput/peek/leak. This was adata race in the default configuration (in-memory bucket + scheduled leak).
MultiprocessBucketaliases this lock to its shared cross-process lock. (#302)wall-clock epoch time instead of monotonic time. The monotonic fallback
was ~5 orders of magnitude smaller than the stored epoch-ms timestamps and
would corrupt every window comparison and leak bound. (#302)
bucket after every bucket had been disposed previously raised
RuntimeError: threads can only be started once. (#302)Limiterpicklable after theInMemoryBucketlock addition. (#302)Performance & Scalability
a long wait on one key no longer serializes acquisitions for every other key
sharing the limiter. (#304)
ZADDs in bounded chunks inside the atomicLua script, lowering latency for high-weight puts. (#284)
Internal / Refactor
share the delay-step decision across the sync and async branches. (#303)
is_asyncbucket attribute so theLeakerno longer detectsasync by executing a side-effecting
leak(0)probe.RedisBucketstill probesbecause it may wrap either a sync or an async client. (#305)
Algorithm/Decisionseam (SlidingWindowLog) that thebuilt-in buckets delegate their per-rate admit decision and leak bound to —
the foundation for pluggable algorithms (e.g. GCRA, sliding-window-counter) in
a future release. (#307)
Documentation
RedisBucketkeeps one sorted-set member per consumed unit, andthat long-window / high-volume quotas may want a coarser counter-based backend
for bounded memory. (#284)
CI
attaches the built
dist/*artifacts, in addition to publishing to PyPI.v4.3.1Compare Source
Performance and maintenance release. No API or behavior changes.
Performance
weightunit-rows in a single statement(
SELECT … FROM generate_series) instead of one INSERT per unit — ~3.4×faster weighted puts and a shorter
EXCLUSIVElock hold. (#296)(
COUNT(*) FILTER) instead of one round trip per rate — ~2× fastermulti-rate checks, fewer round trips under the lock. (#297)
SingleBucketFactory.wrap_item: inline the sync fast path (noper-acquire closures) — ~23% faster item wrapping on the hot path. (#296)
_delay_waiterinto a singleshared helper. (#294)
Documentation
outdated architecture image with a component-level Mermaid diagram that
renders on both GitHub and ReadTheDocs. (#293, #295)
CI
(
checkout@v5,setup-python@v6,setup-uv@v7,upload-artifact@v6,download-artifact@v7). (#295)v4.3.0Compare Source
Bug-fix and hardening release. It contains a few breaking changes that affect
only edge or undocumented usage — see Breaking Changes below.
Breaking Changes
ValueErrorat bucket construction insteadof being silently mis-enforced. A valid list is ordered by strictly
increasing interval, with strictly increasing limits and non-increasing
density (the "generous-before-tight" contract). (#239)
binary_searchhas been removed from the public API. It was an undocumentedinternal helper, now replaced internally by the standard library
bisect. (#290)PgQueriesSQL templates now use bound%sparameters instead of the{offset}/{timestamp}format placeholders. (#233)Security
interpolation. The user-supplied item name (SQLite) and the table name
(Postgres) are now bound/quoted, closing a SQL-injection vector and fixing
crashes on names containing quotes or other metacharacters. (#233, #244)
Fixed
try_acquireno longer busy-spins (burning CPU until the nextbackground leak) or spuriously times out when
buffer_ms=0;waiting()nowclears the inclusive window lower bound correctly. (#289)
try_acquire_async(timeout=0)now succeeds when capacity is availableinstead of always returning
False. (#289)leak()no longer raisesAttributeErrorwhen invoked on a closedconnection during teardown (fixes the unstable
test_sqlite_filelock_bucket). (#244)fixing a latent
leak()bug when unsorted rates were passed to the Redis,SQLite, or Postgres buckets. (#239)
Changed
binary_searchwith the standard librarybisect. (#290)Documentation
clock=,raise_when_fail, andmax_delayparameters) and documented how to use acustom / distributed clock in v4. (#261)
v4.2.0Compare Source
What's Changed
_delay_waiteragainst negative wait values from bucket backends by @Copilot in #278New Contributors
Full Changelog: vutran1710/PyrateLimiter@v4.1.0...v4.2.0
v4.1.0Compare Source
What's Changed
__init__.pyfiles by @Copilot in #266New Contributors
Full Changelog: vutran1710/PyrateLimiter@v4.0.2...v4.1.0
v4.0.2Compare Source
Include missing docs & tests
What's Changed
Full Changelog: vutran1710/PyrateLimiter@v4.0.1...v4.0.2
v4.0.1Compare Source
Nothing, just the same as v4.0.0
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.