rate_limiter module

class rate_limiter.RateLimiter(max_per_minute=30)[מקור]

Bases: object

מגביל קצב פשוט בזיכרון לפי משתמש.

  • חלון מתגלגל של 60 שניות

  • ללא תלות חיצונית

פרמטרים:

max_per_minute (int)

__init__(max_per_minute=30)[מקור]
פרמטרים:

max_per_minute (int)

Return type:

None

async check_rate_limit(user_id)[מקור]

מחזיר True אם מותר להמשיך, אחרת False.

Return type:

bool

פרמטרים:

user_id (int)

async get_current_usage_ratio(user_id)[מקור]

מחזיר יחס שימוש נוכחי בחלון (0.0–1.0).

מנקה ערכים ישנים לפני החישוב כדי לשקף את החלון המתגלגל של 60 שניות.

Return type:

float

פרמטרים:

user_id (int)