Other Classes¶
The following classes are provided for complete documentation. You should not normally need to work with them directly.
Rate Limit¶
- class prawcore.rate_limit.RateLimiter(*, window_size)¶
Facilitates the rate limiting of requests to Reddit.
Rate limits are controlled based on feedback from requests to Reddit.
- Parameters:
window_size (int)
- call(request_function, set_header_callback, *args, **kwargs)¶
Rate limit the call to
request_function.- Parameters:
request_function (
Callable[[Any],Response]) – A function call that returns an HTTP response object.set_header_callback (
Callable[[],dict[str,str]]) – A callback function used to set the request headers. This callback is called after any necessary sleep time occurs.args (
Any) – The positional arguments torequest_function.kwargs (
Any) – The keyword arguments torequest_function.
- Return type:
- update(response_headers)¶
Update the state of the rate limiter based on the response headers.
This method should only be called following an HTTP request to Reddit.
Response headers that do not contain
x-ratelimitfields will be treated as a single request. This behavior is to error on the safe-side as such responses should trigger exceptions that indicate invalid behavior.
Retry Strategies¶
- class prawcore.sessions.RetryStrategy¶
An abstract class for scheduling request retries.
The strategy controls both the number and frequency of retry attempts.
Instances of this class are immutable.
- abstractmethod consume_available_retry()¶
Allow one fewer retry.
- Return type:
- class prawcore.sessions.FiniteRetryStrategy(retries=2)¶
A
RetryStrategythat retries requests a finite number of times.- Parameters:
retries (int)
- consume_available_retry()¶
Allow one fewer retry.
- Return type:
- should_retry_on_failure()¶
Return
Trueif and only if the strategy will allow another retry.- Return type: