sentinelhub.download.models
Module implementing model classes to store download-related parameters and data.
- class sentinelhub.download.models.DownloadRequest(url=None, headers=<factory>, request_type=RequestType.GET, post_values=None, use_session=False, data_type=MimeType.RAW, save_response=False, data_folder=None, filename=None, return_data=True, extra_params=<factory>)[source]
Bases:
object
A class defining a single download request.
The class is a container with all parameters needed to execute a single download request and save or return downloaded data.
- Parameters:
url (str | None) – A URL from where to download
headers (Dict[str, Any]) – Headers of an HTTP request
request_type (RequestType) – Type of request, either GET or POST. Default is RequestType.GET
post_values (Dict[str, Any] | None) – A dictionary of values that will be sent with a POST request. Default is None
use_session (bool) – A flag that specifies if the download request will require a session header
data_type (MimeType) – An expected file format of downloaded data. Default is MimeType.RAW
save_response (bool) – A flag defining if the downloaded data will be saved to disk. Default is False.
data_folder (str | None) – A folder path where the fetched data will be (or already is) saved. Default is None
filename (str | None) – A custom filename where the data will be saved. By default, data will be saved in a folder which name are hashed request parameters.
return_data (bool) – A flag defining if the downloaded data will be returned as an output of download procedure. Default is True.
extra_params (dict[str, Any]) – Any additional parameters.
- url: str | None = None
- headers: Dict[str, Any]
- request_type: RequestType = 'GET'
- post_values: Dict[str, Any] | None = None
- use_session: bool = False
- save_response: bool = False
- data_folder: str | None = None
- filename: str | None = None
- return_data: bool = True
- extra_params: dict[str, Any]
- raise_if_invalid()[source]
Method that raises an error if something is wrong with request parameters
- Raises:
ValueError
- Return type:
None
- get_request_params(include_metadata=False)[source]
Provides parameters that define the request in form of a dictionary
- Parameters:
include_metadata (bool) – A flag defining if also metadata parameters should be included, such as headers and current time
- Returns:
A dictionary of parameters
- Return type:
Dict[str, Any]
- get_hashed_name()[source]
It takes request url and payload and calculates a unique hashed string from them.
- Returns:
A hashed string
- Return type:
str
- class sentinelhub.download.models.DownloadResponse(request, content, headers=<factory>, status_code=None, elapsed=None)[source]
Bases:
object
A class defining a single download response.
- Parameters:
request (DownloadRequest) – A download request object for which the response is obtained.
content (bytes) – Raw encoded data of the response.
headers (Dict[str, Any]) – Headers obtained with the response.
status_code (int | None) – Status code of the response.
elapsed (float | None) – Number of seconds it took to obtain the response.
- request: DownloadRequest
- content: bytes
- headers: Dict[str, Any]
- status_code: int | None = None
- elapsed: float | None = None
- classmethod from_response(response, request)[source]
Creates DownloadResponse object from obtained from a service response and request info.
- Param:
A service response object.
- Param:
A request for which response was obtained.
- Returns:
An instance of a download response object.
- Parameters:
response (Response) –
request (DownloadRequest) –
- Return type:
- classmethod from_local(request)[source]
Creates DownloadResponse object by loading it from locally cached data.
- Parameters:
request (DownloadRequest) – A request object for which data is cached locally.
- Returns:
An instance of a download response object.
- Return type: