A simple ratelimiter for aiohttp.web
Project description
aiohttp-ratelimiter
This library allows you to add a rate limit to your aiohttp.web app.
Install from git
python -m pip install git+https://github.com/Nebulizer1213/aiohttp-ratelimiter
Install from pypi
python -m pip install aiohttp-ratelimiter
Example
from aiohttplimiter import limit, default_keyfunc
from aiohttp import web
app = web.Application()
routes = web.RouteTableDef()
# This endpoint can only be requested one time per second per IP address.
@routes.get("/")
@limit(ratelimit="1/1", keyfunc=default_keyfunc)
async def test(request):
return web.Response(text="test")
app.add_routes(routes)
web.run_app(app)
If you want to sleep until the ratelimit is over instead of throwing a 429 exception you can set sleep_while_limited to True.
from aiohttplimiter import limit, default_keyfunc
from aiohttp import web
app = web.Application()
routes = web.RouteTableDef()
@routes.get("/")
@limit(ratelimit="1/1", keyfunc=default_keyfunc, sleep_while_limited=True)
async def test(request):
return web.Response(text="test")
app.add_routes(routes)
web.run_app(app)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for aiohttp-ratelimiter-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6a0e8ad394c548b5a1219fb17dcec44d060ddb11cea7a36a673d10ce0b322be |
|
MD5 | 3ea4630cce3cb8c0172c318a5f889a0a |
|
BLAKE2b-256 | cee8bc9eb3eac99a9b576f772e90abc29d27ad88cd5fc4729c3c322e8697cf2c |