-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fixes, changed hot rate limit stings are parsed, and added memcac…
…hed storage option.
- Loading branch information
1 parent
4d3cb06
commit 92c361f
Showing
5 changed files
with
16 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
Metadata-Version: 2.1 | ||
Name: aiohttp-ratelimiter | ||
Version: 3.5.3 | ||
Version: 4.0.0 | ||
Summary: A simple rate limiter for aiohttp.web | ||
Home-page: https://jgltechnologies.com/aiohttplimiter | ||
Author: George Luca | ||
Author-email: [email protected] | ||
License: MIT | ||
Platform: UNKNOWN | ||
Classifier: Development Status :: 4 - Beta | ||
Classifier: Development Status :: 5 - Production/Stable | ||
Classifier: Intended Audience :: Developers | ||
Classifier: License :: OSI Approved :: MIT License | ||
Classifier: Programming Language :: Python :: 3 | ||
|
@@ -21,7 +21,7 @@ License-File: LICENSE | |
# aiohttp-ratelimiter | ||
|
||
aiohttp-ratelimiter is a rate limiter for the aiohttp.web framework. | ||
This is a new library and we are always looking for people to contribute. If you see something wrong with the code or want to add a feature, please create a pull request | ||
This is a new library, and we are always looking for people to contribute. If you see something wrong with the code or want to add a feature, please create a pull request | ||
on <a href="https://jgltechnologies.com/aiohttplimiter">our github</a>. | ||
|
||
|
||
|
@@ -42,16 +42,21 @@ Example | |
|
||
```python | ||
from aiohttp import web | ||
from aiohttplimiter import default_keyfunc, Limiter | ||
from aiohttplimiter import default_keyfunc, Limiter, RedisLimiter, MemcachedLimiter | ||
|
||
app = web.Application() | ||
routes = web.RouteTableDef() | ||
|
||
# In Memory | ||
limiter = Limiter(keyfunc=default_keyfunc) | ||
# Redis | ||
limiter = RedisLimiter(keyfunc=default_keyfunc, uri="redis://localhost:6379") | ||
# Memcached | ||
limiter = MemcachedLimiter(keyfunc=default_keyfunc, uri="redis://localhost:11211") | ||
|
||
@routes.get("/") | ||
# This endpoint can only be requested 1 time per second per IP address | ||
@limiter.limit("1/1") | ||
@limiter.limit("1/second") | ||
async def home(request): | ||
return web.Response(text="test") | ||
|
||
|
@@ -75,7 +80,7 @@ routes = web.RouteTableDef() | |
limiter = Limiter(keyfunc=default_keyfunc, exempt_ips={"192.168.1.245"}) | ||
|
||
@routes.get("/") | ||
@limiter.limit("1/1") | ||
@limiter.limit("3/5minutes") | ||
async def test(request): | ||
return web.Response(text="test") | ||
|
||
|
@@ -95,7 +100,7 @@ def handler(request: web.Request, exc: RateLimitExceeded): | |
# If for some reason you want to allow the request, return aiohttplimitertest.Allow(). | ||
if some_condition: | ||
return Allow() | ||
return web.Response(text="Too many requests", status=429) | ||
return web.Response(text=f"Too many requests", status=429) | ||
|
||
limiter = Limiter(keyfunc=default_keyfunc, error_handler=handler) | ||
``` | ||
|
@@ -106,7 +111,7 @@ If multiple paths use one handler like this: | |
```python | ||
@routes.get("/") | ||
@routes.get("/home") | ||
@limiter.limit("5/1") | ||
@limiter.limit("5/hour") | ||
def home(request): | ||
return web.Response(text="Hello") | ||
``` | ||
|
@@ -118,22 +123,11 @@ Then they will have separate rate limits. To prevent this use the path_id kwarg. | |
```python | ||
@routes.get("/") | ||
@routes.get("/home") | ||
@limiter.limit("5/1", path_id="home") | ||
@limiter.limit("2/3days", path_id="home") | ||
def home(request): | ||
return web.Response(text="Hello") | ||
``` | ||
|
||
<br> | ||
|
||
If you want to use Redis instead, use the RedisLimiter class. | ||
|
||
```python | ||
from aiohttplimiter import RedisLimiter, default_keyfunc | ||
|
||
|
||
limiter = RedisLimiter(keyfunc=default_keyfunc, uri="redis://username:password@host:port") | ||
``` | ||
|
||
|
||
|
||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
aiohttp | ||
limits | ||
coredis | ||
emcache |
Binary file not shown.
Binary file not shown.