Ellar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications.
Introduction
A rate limit module for Ellar
Installation
$(venv) pip install ellar-throttler
Configure ThrottlerModule
We need to set up the ThrottlerModule to be able for configuring throttling mechanisms for the entire application.
from ellar.common import Module
from ellar_throttler import AnonymousThrottler, ThrottlerModule, UserThrottler
@Module(
modules=(
ThrottlerModule.setup(
throttlers=[
AnonymousThrottler(limit=100, ttl=60*5), # 100 requests per 5mins
UserThrottler(limit=1000, ttl=60*60*24) # 1000 requests per day
]
),
)
)
class AppModule:
pass
Applying Throttling to Controllers
from ellar.common import Controller, get
from ellar_throttler import Throttle, AnonymousThrottler, UserThrottler
from ellar.di import injectable
@injectable()
class AppService:
def success(self, use_auth: bool):
message = "success"
if use_auth:
message += " for Authenticated user"
return {message: True}
def ignored(self, use_auth: bool):
message = "ignored"
if use_auth:
message += " for Authenticated user"
return {message: True}
@Throttle(intercept=True)
@Controller("/limit")
class LimitController:
def __init__(self, app_service: AppService):
self.app_service = app_service
@get()
def get_throttled(self, use_auth: bool):
return self.app_service.success(use_auth)
@get("/shorter")
@Throttle(anon={"limit": 3, "ttl": 5}, user={"limit": 3, "ttl": 3}) # overriding anon and user throttler config
def get_shorter(self, use_auth: bool):
return self.app_service.success(use_auth)
@get("/shorter-inline-throttling")
@Throttle(AnonymousThrottler(ttl=5, limit=3), UserThrottler(ttl=3, limit=3)) # overriding global throttling options
def get_shorter_inline_version(self, use_auth: bool):
return self.app_service.success(use_auth)
References
License
Ellar is MIT licensed.
Metadata
Release files for ellar-throttler 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ellar_throttler-0.1.7.tar.gz | 10.7 kB | Without provenance | Details for ellar_throttler-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ellar_throttler-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for ellar_throttler-0.1.7-py3-none-any.whl |
Total release size: 26.7 kB
Release files / ellar_throttler-0.1.7.tar.gz
| Download URL | ellar_throttler-0.1.7.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e33b6ee56a7386875261f4cd383e2047e79e3c76e703b4d361a96081144d98e9
|
|
BLAKE2b-256 checksum How to use checksums |
c9c05b8f14b33c60f7c8715f38cd907e6fb0e3e391f797247ff0659ac31578fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|
Release files / ellar_throttler-0.1.7-py3-none-any.whl
| Download URL | ellar_throttler-0.1.7-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d6349f7e87015746c813f8eaefa3cee046ed28d289345a5f05df6b08d8b1cbb
|
|
BLAKE2b-256 checksum How to use checksums |
4d12010660b8530389dffc7ca0e32283415b3d003215eab46e1640db853b59d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|
Security for ellar-throttler 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.