Limiter - in Utility Submodule: Functions and Classes#

This module provides a mixture of helpers to support rate limiting and also functions for conversion?

TODO: look into whether total_seconds relates to limiter actions or unit conversion

Summary Functions#

total_seconds(td)

Alternative to datetime.timedelta.total_seconds total_seconds() only available since Python 2.7 https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds

get_rates_from_response_headers(headers)

Returns a namedtuple with values for short - and long usage and limit rates found in provided HTTP response headers :param headers: HTTP response headers :type headers: dict :return: namedtuple with request rates or None if no rate-limit headers present in response.

get_seconds_until_next_quarter([now])

Returns the number of seconds until the next quarter of an hour.

get_seconds_until_next_day([now])

Returns the number of seconds until the next day (utc midnight).

Summary Classes#

XRateLimitRule(limits[, force_limits])

SleepingRateLimitRule([priority, ...])

A rate limit rule that can be prioritized and can dynamically adapt its limits based on API responses.

RateLimitRule(requests, seconds[, raise_exc])

RateLimiter()

DefaultRateLimiter()

Implements something similar to the default rate limit for Strava apps.