Module implementing rate limiting logic for Sentinel Hub service

class sentinelhub.sentinelhub_rate_limit.SentinelHubRateLimit(num_processes=1, minimum_wait_time=0.05, maximum_wait_time=60.0)[source]

Bases: object

Class implementing rate limiting logic of Sentinel Hub service

It has 2 public methods:

  • register_next - tells if next download can start or if not, what is the wait before it can be asked again
  • update - updates expectations according to headers obtained from download

The rate limiting object is collecting information about the status of rate limiting policy buckets from Sentinel Hub service. According to this information and a feedback from download requests it adapts expectations about when the next download attempt will be possible.

  • num_processes (int) – Number of parallel download processes running.
  • minimum_wait_time (float) – Minimum wait time between two consecutive download requests in seconds.
  • maximum_wait_time (float) – Maximum wait time between two consecutive download requests in seconds.

Determines if next download request can start or not by returning the waiting time in seconds.


Update the next possible download time if the service has responded with the rate limit

class sentinelhub.sentinelhub_rate_limit.PolicyBucket(policy_type, policy_payload)[source]

Bases: object

A class representing Sentinel Hub policy bucket

  • policy_type (PolicyType or str) – A type of policy
  • policy_payload (dict) – A dictionary of policy parameters

Variable content can be accessed as a property

count_cost_per_second(elapsed_time, new_content)[source]

Calculates the cost per second for the bucket given the elapsed time and the new content.

In the calculation it assumes that during the elapsed time bucket was being filled all the time - i.e. it assumes the bucket has never been full for a non-zero amount of time in the elapsed time period.

get_wait_time(elapsed_time, process_num, cost_per_request, requests_completed, buffer_cost=0.5)[source]

Expected time a user would have to wait for this bucket


Checks if bucket counts requests


Checks if bucket has a fixed number of requests

class sentinelhub.sentinelhub_rate_limit.PolicyType[source]

Bases: enum.Enum

Enum defining different types of policies