Skip to content

Commit

Permalink
bug fixes, changed hot rate limit stings are parsed, and added memcac…
Browse files Browse the repository at this point in the history
…hed storage option.
  • Loading branch information
Nebulizer1213 committed Jul 17, 2022
1 parent 4d3cb06 commit 92c361f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
34 changes: 14 additions & 20 deletions aiohttp_ratelimiter.egg-info/PKG-INFO
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
Expand All @@ -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>.


Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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)
```
Expand All @@ -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")
```
Expand All @@ -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")
```




Expand Down
1 change: 1 addition & 0 deletions aiohttp_ratelimiter.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ aiohttp_ratelimiter.egg-info/requires.txt
aiohttp_ratelimiter.egg-info/top_level.txt
aiohttplimiter/__init__.py
aiohttplimiter/limiter.py
aiohttplimiter/memcached_limiter.py
aiohttplimiter/memory_limiter.py
aiohttplimiter/redis_limiter.py
1 change: 1 addition & 0 deletions aiohttp_ratelimiter.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp
limits
coredis
emcache
Binary file removed dist/aiohttp-ratelimiter-3.5.3.tar.gz
Binary file not shown.
Binary file added dist/aiohttp-ratelimiter-4.0.0.tar.gz
Binary file not shown.

0 comments on commit 92c361f

Please sign in to comment.