Skip to content

Class swarmauri_core.rate_limits.IRateLimit.IRateLimit

swarmauri_core.rate_limits.IRateLimit.IRateLimit

Bases: ABC

Interface for rate limiting mechanisms.

allow abstractmethod

allow(tokens=1)

Attempt to consume tokens and return whether the request is allowed.

Source code in swarmauri_core/rate_limits/IRateLimit.py
7
8
9
@abstractmethod
def allow(self, tokens: int = 1) -> bool:
    """Attempt to consume tokens and return whether the request is allowed."""

available_tokens abstractmethod

available_tokens()

Return the number of currently available tokens.

Source code in swarmauri_core/rate_limits/IRateLimit.py
11
12
13
@abstractmethod
def available_tokens(self) -> int:
    """Return the number of currently available tokens."""

refill abstractmethod

refill()

Refill tokens based on elapsed time or other strategy.

Source code in swarmauri_core/rate_limits/IRateLimit.py
15
16
17
@abstractmethod
def refill(self) -> None:
    """Refill tokens based on elapsed time or other strategy."""