Limiter for Sanic.
Project description
sanic_limiter
Require
Python 3.7+
Redis
Sources
git clone https://github.com/kingchao1024/sanic_limiter.git
Install (Python 3.7+)
pip install limiter-for-sanic
Introduce
A Sanic current limiter based on the sliding window idea.
Quickstart
Demo for quickstart:
from sanic import Sanic
from aioredis import from_url
from sanic.response import text
from limiter_for_sanic import CounterSildeWindowLimiter
app = Sanic(__name__)
app.config['REDIS'] = 'redis://locahost'
# or
# setattr(app.ctx, 'redis', await from_url('redis://locahost'))
limiter = CounterSildeWindowLimiter(app)
@app.get('/')
@limiter.limit()
async def index(request: Request):
return text('HELLO')
app.run(host="0.0.0.0", port=5000, dev=True)
Points Used
- Redis lua
- Redis list
- Sanic background tasks
Redis transactions
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
Built Distribution
Close
Hashes for limiter_for_sanic-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a243c75ca24c9f26c20d1c143538697d775f27de8e8fa2421bd6597a03b701 |
|
MD5 | 178a6e8204303c5c4ec2abfeeaf30df9 |
|
BLAKE2b-256 | 0fd0bb5d7cba95f32f8bee96747a0d653c774f7c47fd9f3e77a210b835020c28 |