Why use async?
When working with external datasets, such as Tilebox datasets, loading data may take some time. To speed up this process, you can run requests in parallel. While you can use multi-threading or multi-processing, which can be complex, often times a simpler option is to perform data loading tasks asynchronously using coroutines andasyncio.
Switching to an async datasets client
To switch to the async client, change the import statement for theClient. The example below illustrates this change.
await for operations that interact with the Tilebox API.
Jupyter notebooks and similar interactive environments support asynchronous code execution. You can use
await some_async_call() as the output of a code cell.Accessing assets asynchronously
The storage client is asynchronous. Resolve the assets from one queried datapoint, then await the storage operation:Python
Downloading assets concurrently
Run independent storage operations concurrently withasyncio.gather. This example continues from the preceding query and downloads the datapoint’s red, green, and blue bands:
Python
Async workflows
Python workflow tasks can defineexecute with async def. The runner waits for the method to complete, so you can await asynchronous APIs such as Tilebox Storage directly without wrapping the task code in asyncio.run().
For example, a task can read a small group of assets concurrently:
Python
execute asynchronous does not cause separate workflow tasks to run concurrently within one runner. It only lets one task perform related I/O concurrently.