Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

limiter_for_sanic-0.1.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

limiter_for_sanic-0.1.0-py2.py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page