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 (Optional[str]) – 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 (Optional[Dict[str, Any]]) – 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 (Optional[str]) – A folder path where the fetched data will be (or already is) saved. Default is None

  • filename (Optional[str]) – 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: Optional[str] = None
headers: Dict[str, Any]
request_type: RequestType = 'GET'
post_values: Optional[Dict[str, Any]] = None
use_session: bool = False
data_type: MimeType = 'raw'
save_response: bool = False
data_folder: Optional[str] = None
filename: Optional[str] = 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

get_relative_paths()[source]

A method that calculates file paths relative to data_folder

Returns

Returns a pair of file paths, a request payload path and a response path. If request path is not defined it returns None.

Return type

Tuple[Optional[str], str]

get_storage_paths()[source]

A method that calculates file paths where request payload and response will be saved.

Returns

Returns a pair of file paths, a request payload path and a response path. Each of them can also be None if it is not defined.

Return type

Tuple[Optional[str], Optional[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 (Optional[int]) – Status code of the response.

  • elapsed (Optional[float]) – Number of seconds it took to obtain the response.

request: DownloadRequest
content: bytes
headers: Dict[str, Any]
status_code: Optional[int] = None
elapsed: Optional[float] = 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
Return type

DownloadResponse

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

DownloadResponse

to_local()[source]

Caches data about a request and a response locally.

Return type

None

property response_type: MimeType

Provides the expected mime type of the response data.

decode()[source]

Decodes binary data into a Python object.

Return type

Any

derive(**params)[source]

Create a new response by changing some parameters of the existing one.

Parameters

params (Any) – Any of DownloadResponse attributes.

Returns

A new instance of DownloadResponse with modified parameters

Return type

DownloadResponse