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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

Details for the file limiter_for_sanic-0.1.0.tar.gz.

File metadata

  • Download URL: limiter_for_sanic-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for limiter_for_sanic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa7ce36ce213b3912e6254803bf648214270ddf821fa6f88c07d64f6d3561dfa
MD5 58ebae41c83f51c2280f60dd94c5e037
BLAKE2b-256 b07ba89aa8123b84fc4478c408ec6905cdad97b6da7f13c22ec41cd076b5aeaa

See more details on using hashes here.

File details

Details for the file limiter_for_sanic-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for limiter_for_sanic-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c6a243c75ca24c9f26c20d1c143538697d775f27de8e8fa2421bd6597a03b701
MD5 178a6e8204303c5c4ec2abfeeaf30df9
BLAKE2b-256 0fd0bb5d7cba95f32f8bee96747a0d653c774f7c47fd9f3e77a210b835020c28

See more details on using hashes here.

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