-
-
Notifications
You must be signed in to change notification settings - Fork 3
rate_limiter
#37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
rate_limiter
#37
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements an in-memory rate limiter for FastAPI along with tests and documentation updates, laying the groundwork for a future REDIS-based implementation.
- Adds a rate limiter decorator in fastapi_utilities/rate_limiter/rate_limiter.py
- Introduces comprehensive tests for multiple rate limiting scenarios in tests/test_rate_limiter.py
- Updates documentation in README.md and docs/index.md to describe the new rate limiter
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/test_rate_limiter.py | Added tests covering various rate limiting scenarios |
fastapi_utilities/rate_limiter/rate_limiter.py | Implements the in-memory rate limiter decorator |
fastapi_utilities/rate_limiter/init.py | Exposes the rate limiter decorator |
fastapi_utilities/init.py | Updates package initialization to include the rate limiter |
docs/index.md | Updates documentation and table of contents for the rate limiter |
app.py | Provides sample usage of the rate limiter |
README.md | Updates documentation with details on rate limiter usage |
Files not reviewed (1)
- .vscode/settings.json: Language not supported
request_logs: Dict[str, Tuple[float, int]] = {} | ||
|
Copilot
AI
Mar 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of the global 'request_logs' dictionary is not thread-safe and may lead to race conditions in concurrent environments. Consider protecting its access with an async lock or another concurrency control mechanism.
request_logs: Dict[str, Tuple[float, int]] = {} | |
request_logs: Dict[str, Tuple[float, int]] = {} | |
request_logs_lock = asyncio.Lock() |
Copilot uses AI. Check for mistakes.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #37 +/- ##
==========================================
+ Coverage 73.00% 75.89% +2.89%
==========================================
Files 12 14 +2
Lines 200 224 +24
==========================================
+ Hits 146 170 +24
Misses 54 54 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
In-memory rate limiter
TODO: REDIS one to be implemented later