All Collections
WEkEO Harmonized Data Access
HDA API Client & Rest
What is the HDA API Python Client and how to use it?
What is the HDA API Python Client and how to use it?

In this article we introduce the WEkEO's HDA API Python Client and we will show you how to install it.

David Bina avatar
Written by David Bina
Updated over a week ago

Context


The Harmonized Data Access (HDA) is a unique Application Programming Interface (API) that connects the user and WEkEO’s Copernicus data without extra steps. Thus, the user does not need to download large amounts of data, or adapt a code to each different source.

WEkEO’s REST-based single protocol allows the user to scale and evolve his code, giving easy access to data with homogeneous attributes from the user’s virtual machine, Jupyter Notebook or even a desktop application. The data can be requested through command lines in the user’s own processing environment.

The HDA API got a Python Client that will help you to download and process quickly needed data. Let's see now how to use the HDA API with Python! 🙌

How to use the HDA API


You can follow along the steps of the article to download data in this notebook:

Official documentation

For further information, please visit the WEkEO HDA API documentation.

Step 1. Install the latest version of hda

Run the following command in a terminal in order to install the latest version of HDA:

pip install hda -U

💡WEkEO Pro Tip: all the required packages, including the hda library, are already installed in the default environment miniwekeolab of the WEkEO JupyterHub.

Step 2. Import hda module

Let's import the needed functions:

from hda import Client, Configuration

Step 3. Configure credentials and load hda Client

Afterwards, we must configure user's credentials and load the hda Client.

Let's see most used methods:

Method 1 (not regular users)

Configuration of WEkEO credentials directly in the script:

# Configure user's credentials without a .hdarc
conf = Configuration(user = "username", password = "password")
hda_client = Client(config = conf)

Method 2 (regular users)

Create the .hdarc configuration file as follows:

from pathlib import Path

# Default location expected by hda package
hdarc = Path(Path.home() / '.hdarc')

# Create it only if it does not already exists
if not hdarc.is_file():
import getpass
USERNAME = input('Enter your username: ')
PASSWORD = getpass.getpass('Enter your password: ')

with open(Path.home() / '.hdarc', 'w') as f:
f.write(f'user:{USERNAME}\n')
f.write(f'password:{PASSWORD}\n')

hda_client = Client()

📌Note: be careful, if you created a .hdarc before March 2024, you'll need remove the url indicated in it.

⚠️ This method needs to be done only once. Future calls hda_client = Client() will always retrieve credentials from created file.

Step 4. Create the request and download data

We can now call the .json request (How to get the query) and start the download:

# The JSON query loaded in the "query" variable
query = {
"datasetId": "EO:EEA:DAT:CLMS_HRVPP_VPP",
"boundingBoxValues": [
{
"name": "bbox",
"bbox": [
-9.535920423319538,
42.4682546523869,
-7.036310280709689,
43.99700636050321
]
}
],
"dateRangeSelectValues": [
{
"name": "temporal_interval",
"start": "2020-01-01T00:00:00.000Z",
"end": "2021-01-01T00:00:00.000Z"
}
],
"stringChoiceValues": [
{
"name": "productType",
"value": "TPROD"
},
{
"name": "productGroupId",
"value": "s1"
}
]
}

# Ask the result for the query passed in parameter
matches = hda_client.search(query)

# List the results
print(matches)

# Download results in a directory (e.g. '/tmp')
# Create the directory if it doesn't exist since version 1.14 of hda
matches.download(download_dir="/tmp")

💡WEkEO Pro Tip: the code above will download all files in matches, but it is also possible to easily customize it by slicing the matches object, like:

matches[0].download() # Will only download the first result

matches[-1].download() # Will only download the last result

matches[:10].download() # Will only download the first 10 results

📌Note: in the example above we download the files in a local directory (option 1 in the notebook example). You also have the possibility to download them in a bucket (option 2), but first you need to upgrade your plan to get a tenant.

⚠️ There is a limitation of Request and Orders. More details in this article.

What's next?


If you encounter any issue by following the notebook, please contact the WEkEO Support.

Feel free to check these articles that might be of interest for you:

We are user-driven and we implement users' suggestions, so feel free to contact us:

  • through a chat session available in the bottom right corner of the page

  • via e-mail to our support team (supportATwekeo.eu)

Did this answer your question?