Module implementing rate limiting logic for Sentinel Hub service
- class sentinelhub.download.rate_limit.PolicyType(value)[source]
Enum defining different types of policies
- PROCESSING_UNITS = 'PROCESSING_UNITS'
- REQUESTS = 'REQUESTS'
- class sentinelhub.download.rate_limit.SentinelHubRateLimit(num_processes=1, minimum_wait_time=0.05, maximum_wait_time=60.0)[source]
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.
- RETRY_HEADER = 'Retry-After'
- UNITS_SPENT_HEADER = 'X-ProcessingUnits-Spent'
Determines if next download request can start or not by returning the waiting time in seconds.
- Return type:
- class sentinelhub.download.rate_limit.PolicyBucket(policy_type, policy_payload)[source]
A class representing Sentinel Hub policy bucket
policy_type (PolicyType) – A type of policy
policy_payload (Dict[str, Any]) – A dictionary of policy parameters
- 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