Open
Conversation
Implement WebSocketRateLimiter class compatible with fastapi-limiter API that automatically detects and uses the global RateLimiter's store configuration for consistent rate limiting across HTTP and WebSocket connections. Features: - WebSocketRateLimiter with times/seconds/minutes/hours parameters - WebSocketRateLimitException for rate limit violations - Automatic detection of global store via QUART_RATE_LIMITER_STORE config - Support for context_key parameter to differentiate message types - Compatible with all existing storage backends (Memory, Redis, Valkey) - Fallback to MemoryStore when no global store or app context available - Comprehensive test coverage with real Quart app fixtures - Complete documentation including configuration guide and WebSocket usage Signed-off-by: chredeur <50155089+chredeur@users.noreply.github.com>
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.
Motivation
I often use
fastapi-limiterand noticed that a similar feature was missing inquart-rate-limiter.This PR introduces WebSocket rate limiting, inspired by
fastapi-limiter, while keeping the setup simple.Summary
Adds WebSocket rate limiting that automatically reuses the same store as your HTTP rate limiter no extra configuration required!
What’s New
WebSocketRateLimiterclass with afastapi-limiter-compatible APIWebSocketRateLimitExceptionfor handling rate limit violationsHow It Works
No need to configure your stores twice it works out of the box and keeps HTTP and WebSocket limits in sync.