AlbertUnruhUtils.ratelimit.server module¶
- class AlbertUnruhUtils.ratelimit.server.ServerRateLimit(sections: dict[str, dict[str, int]], retrieve_section: Callable[[...], tuple[str, Union[str, int]]], *, redis: Optional[Redis] = None)¶
Bases:
objectDocs ‘ll come soon… (If you want docs right now you can take a look into
__init__)- Parameters
sections (dict[str, dict[str, int]]) – Parameter
sectionsrequires following structure:`py >>> { ... "<NAME or TYPE (e.g. user, admin etc.)>": { ... # type: int ... "amount": 10 ... ... # type: int ... "interval": 60 # in seconds ... ... # type: int ... "timeout": 60 # in seconds # if a section requests to often then the timeout 'll be applied ... }, ... "<second NAME or TYPE>": { ... ... ... }, ... ... ... } `retrieve_section (Callable[[...], tuple[str, Union[str, int]]]) – This function ‘ll feed all it’s data from the original callable. e.g.
`py >>> @ServerRateLimit({"user": {...}, "admin": {...}}, retrieve) ... def foo(*args, **kwargs) -> ...: ... pass ... >>> def retrieve(*args, **kwargs) -> (str, str): ... '''This is just an example, you have to manage yourself how you ... set it (can also be static by using a simple lambda-expression)''' ... if "admin_id" in kwargs: ... return "admin", 0 ... return "user", 0 `redis (Redis, optional) – An own redis can optionally be set.
Notes
The first return value from
retrieve_sectionis thesection, the second is theidto have every section separated.- section: dict[str, dict[str, int]]¶
- sections¶
- retrieve_section: Callable[[...], tuple[str, Union[str, int]]]¶