A part of the SharingHub server API is dedicated to SharingHub UI. Most routes are not supposed to be called directly,
with the exception of the STAC API that can be requested from your favorite client.
For more information, check-out our tutorials Tutorials and How-to guides.
importtimefrompathlibimportPathimportrequestsfrompystacimportItem,StacIOAUTH_HEADERS={"X-Gitlab-Token":"<your_access_token> or <your_personal_gitlab_token>"}stac_io=StacIO.default()stac_io.headers=AUTH_HEADERSSTAC_API_URL="https://sharinghub.develop.eoepca.org/api/stac/collections/dataset/items/sharinghub-test/wine-dataset"# Get STAC item and download his assetsitem=Item.from_file(STAC_API_URL,stac_io=stac_io)item_assets=[(name,asset)forname,assetinitem.get_assets().items()ifasset.has_role("data")]timestamp=int(time.time())download_path=Path.cwd()/f"{Path(item.id).name}-{timestamp}"print("Download path:",download_path)forname,assetinitem_assets:file_path=download_path/Path(name)file_path.parent.mkdir(parents=True,exist_ok=True)print("- Download: ",asset.href)response=requests.get(asset.href,headers=AUTH_HEADERS)response.raise_for_status()print(" Write",file_path)withfile_path.open("wb")asf:f.write(response.content)print("Done!")
You must set the X-Gitlab-Token of AUTH_HEADERS with an access token of read_api scope.
This script:
Load a pystac.Item from a SharingHub. The item can represent an AI model, or a dataset.
Define a download path from the item STAC id and current timestamp.