Python API

Quickstart

# connect to the API
from sentinelsat.sentinel import SentinelAPI, get_coordinates
api = SentinelAPI('user', 'password', 'https://scihub.copernicus.eu/dhus')

# download single scene by known product id
api.download(<product_id>)

# search by polygon, time, and SciHub query keywords
api.query(get_coordinates(map.geojson), \
          "20151219", date(2015, 12, 29), \
          keywords={"platformname": "Sentinel-2", \
                    "cloudcoverpercentage": "[0 TO 30]"})

# download all results from the search
api.download_all()

# GeoJSON FeatureCollection containing footprints and metadata of the scenes
api.get_footprints()

Valid search query keywords can be found at the ESA SciHub documentation.

API

class sentinelsat.sentinel.SentinelAPI(user, password, api_url='https://scihub.copernicus.eu/apihub/')

Class to connect to Sentinel Data Hub, search and download imagery.

Parameters:

user : string

username for DataHub

password : string

password for DataHub

api_url : string, optional

URL of the DataHub defaults to ‘https://scihub.copernicus.eu/apihub

Attributes

session (requests.Session object) Session to connect to DataHub
api_url (str) URL to the DataHub

Methods

download(id[, path, checksum]) Download a product using homura’s download function.
download_all([path, checksum]) Download all products using homura’s download function.
format_url(area[, initial_date, end_date]) Create the URL to access the SciHub API, defining the max quantity of results to 15000 items.
get_footprints() Return the footprints of the resulting scenes in GeoJSON format
get_product_info(id) Access SciHub API to get info about a Product.
get_products() Return the result of the Query in json format.
get_products_size() Return the total filesize in Gb of all products in the query
query(area[, initial_date, end_date]) Query the SciHub API with the coordinates of an area, a date inverval and any other search keywords accepted by the SciHub API.
download(id, path='.', checksum=False, **kwargs)

Download a product using homura’s download function.

If you don’t pass the title of the product, it will use the id as filename. Further keyword arguments are passed to the homura.download() function.

download_all(path='.', checksum=False, **kwargs)

Download all products using homura’s download function.

It will use the products id as filenames. If the checksum calculation fails a list with tuples of filename and product ids of the corrupt scenes will be returned. Further keyword arguments are passed to the homura.download() function.

format_url(area, initial_date=None, end_date=datetime.datetime(2016, 9, 27, 8, 58, 22, 831065), **keywords)

Create the URL to access the SciHub API, defining the max quantity of results to 15000 items.

get_footprints()

Return the footprints of the resulting scenes in GeoJSON format

get_product_info(id)

Access SciHub API to get info about a Product. Returns a dict containing the id, title, size, md5sum, date, footprint and download url of the Product. The date field receives the Start ContentDate of the API.

get_products()

Return the result of the Query in json format.

get_products_size()

Return the total filesize in Gb of all products in the query

query(area, initial_date=None, end_date=datetime.datetime(2016, 9, 27, 8, 58, 22, 831032), **keywords)

Query the SciHub API with the coordinates of an area, a date inverval and any other search keywords accepted by the SciHub API.

sentinelsat.sentinel.convert_timestamp(in_date)

Convert the timestamp received from Products API, to YYYY-MM-DDThh:mm:ssZ string format.

sentinelsat.sentinel.format_date(in_date)

Format date or datetime input or a YYYYMMDD string input to YYYY-MM-DDThh:mm:ssZ string format. In case you pass an

sentinelsat.sentinel.get_coordinates(geojson_file, feature_number=0)

Return the coordinates of a polygon of a GeoJSON file.

Parameters:

geojson_file : str

location of GeoJSON file_path

feature_number : int

Feature to extract polygon from (in case of MultiPolygon FeatureCollection), defaults to first Feature

Returns:

polygon coordinates

string of comma separated coordinate tuples to be used by SentinelAPI

sentinelsat.sentinel.md5_compare(file_path, checksum, block_size=8192)

Compare a given md5 checksum with one calculated from a file