-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add rate limiting middleware example #11969
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?
Add rate limiting middleware example #11969
Conversation
This example demonstrates how to implement client-side rate limiting using the token bucket algorithm with support for: - Configurable rate and burst size - Per-domain rate limiting for multi-host scenarios - Automatic Retry-After header handling Includes a self-contained test server for demonstration.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11969 +/- ##
=======================================
Coverage 98.75% 98.75%
=======================================
Files 127 127
Lines 44655 44655
Branches 2367 2367
=======================================
Hits 44101 44101
Misses 393 393
Partials 161 161
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
@Dreamsorcerer do we have any guidance on the examples folder? Some of those files are decade-old and I, for example, never really look in there. @rodrigobnogueira would you be interested in trying to get pytest to run the examples and getting code coverage as acceptance tests? |
Yes @webknjaz , I can try that to get pytest to run the examples, but I suppose the examples guidance should be the first step, because some examples may not comply. Guidance draft:
Potential tweaks of the rule above: if an example must use an external dep (e.g., for integrating with a database like asyncpg in a real-world demo), it should include a clear setup section at the top, like a requirements.txt snippet or install command.
|
|
Here is a comprehensive examples scenario with the help of Gemini. Proposal for Guidance for Examples after the Detailed Status section. I think we can change the existing examples to comply to the proposal. I could try that, but I think I need a strategy from you guys. Do I need to open a issue? Can I submit one PR for each adjusted example? Status Report on ExamplesThis report summarizes the execution status of all example scripts in the Summary
Note: Files that serve as helpers (e.g., Detailed Status
Guidance for ExamplesTo ensure the 1. Zero External DependenciesExamples should run using only
2. CI-Ready & Non-InteractiveExamples must be fully runnable from start to finish without blocking on user input.
3. Modern Asyncio StandardsExamples must use modern, recommended
4. Self-Documentation & ValidationEach example should be self-explanatory and, ideally, self-validating.
|
Not particularly. This PR is still open on my computer to review, will get back to it soon enough.
I guess the question is whether all examples should be cluttered with tests? We have mypy running on them which atleast avoids regular API breakage like we often had in the past. |
What do these changes do?
Adds a new example (
examples/rate_limit_middleware.py) demonstrating rate limiting middleware for the aiohttp client using the token bucket algorithm.Features:
Retry-Afterheader handlingAre there changes in behavior for the user?
No. This is a new example file only — no changes to the aiohttp library code.
Is it a substantial burden for the maintainers to support this?
No. This is a standalone example file demonstrating existing middleware functionality. It uses stable public APIs and doesn't add new library code. Maintenance burden is minimal.
Related issue number
N/A — New example contribution.
Checklist
CONTRIBUTORS.txtCHANGES/folder