tutorialsreferenceguide

Getting started with the SPAI Framework

This step-by-step tutorial will help you get started with SPAI, an end-to-end platform for developers that allows you to create and deploy AI4EO applications.

What is SPAI?

SPAI stands for Satellite Processing Application Interface and it is a complete development framework that allows you to create and deploy applications based on Earth Observation data in the cloud. It is designed to be easy to use, so you can focus on writing your code and let us take care of the rest.

With SPAI you can create SPAI projects, which can consist of storage, processing scripts, APIs, user interfaces and Jupyter Notebooks. You can develop, test and run your projects locally and then deploy in the cloud with a single command. We will take care of provisioning the necessary resources in the cloud and managing them for you. Once your project is deployed, you will have access the logs and get public URLs for your APIs, UIs and notebooks.

Thanks to SPAI it has never been easier to create and deploy AI4EO applications 🚀

SPAI also provides a Python library that you can use in your applications. It will give your streamlined access to a wide range of data sources, processing algorithms (including AI models) and analytics capabilities. All through a simple and unified interface that integrates the most popular third party services and solutions.

SPAI is compatible with existing solutions, so you can integrate it with other tools such as QGIS.

Join our Discord to be part of the community, get in touch with other developers and be part in shaping the future of Earth Observation 🛰️.

Installation

To start using SPAI, first install it on your machine. Make sure you have Python installed, then run the following command in your terminal:

pip install spai

Once the installation is complete, you can verify that SPAI is installed by running the following command:

spai version

and see all the different commands with

spai --help

Your first project

The easiest way to start a new SPAI project is by running the init command, followed by the name you want to give to your project.

spai init my-project
Replace `my-project` with the name you want for your project. Once the project is created, a new folder should be created with the name of your project.

Project structure

Every SPAI project follows the same structure:

/my-project
 |- /scripts
     |- /my-script-1
        |- main.py
        |- requirements.txt
        |- .env
     |- /my-script-2
     |- ...
 |- /apis
     |- /my-api-1
        |- main.py
        |- requirements.txt
        |- .env
     |- /my-api-2
     |- ...
 |- /uis
     |- /my-ui-1
        |- main.py
        |- requirements.txt
        |- .env
     |- /my-ui-2
     |- ...
 |- /notebooks
     |- /my-notebook-1
        |- main.ipynb
        |- requirements.txt
        |- .env
     |- /my-notebook-2
     |- ...
  |- spai.config.yaml
  |- spai.vars.json

The scripts, apis, uis and notebooks folders are where you will write your code. Each folder contains a subfolder for each of your scripts, APIs, UIs and notebooks, respectively. Each subfolder contains the code for the specific script, API, UI or notebook, as well as a requirements.txt file and a .env file.

The spai.config.yaml file contains the configuration for your project, which will tell SPAI how to run your project locally or deploy it in the cloud. For now, let’s igonre the spai.vars.json file.

You can learn more about the project structure here.

Running your project locally

Before running your project for the first time, please make sure you do the following.

Install the required dependencies for the project.

spai install

Navigate inside your project folder and run the following command to start your project locally:

spai run

If everything works as expected, you should have a project running with the following services:

/my-project
 |- /scripts
     |- /downloader
        |- main.py -> downloads latest Sentinel-2 images on a given AoI
        |- requirements.txt
     |- /analytics
        |- main.py -> compute analytics on the downloaded images
        |- requirements.txt
 |- /apis
     |- /analytics
        |- main.py -> serve the compute analytics through an API
        |- requirements.txt
     |- /xyz
        |- main.py -> serve the images through an XYZ tiler API
        |- requirements.txt
 |- /uis
     |- /map
        |- main.py -> visualize images and analytics on an interactive web UI
        |- requirements.txt
 |- /notebooks
     |- /my-notebook-1
        |- main.ipynb -> visualize analytics on an interactive notebook
        |- requirements.txt
  |- spai.config.yaml -> define storage, cronjobs, ports, etc.

You can interact with the APIs, notebook and UI at the specified ports on your localhost. The scripts will be running in the background every minute. You can check the logs of the services in your terminal.

Feel free to modify the code and configuration to adapt it to your needs.

Deploying your project in the cloud

Deploying your project in the cloud is as easy as running the following command:

spai deploy

But before, make sure you make the following two changes:

  1. Change the type of the storage in spai.config.yaml to s3, so your data is stored in a cloud bucket.
  2. Change the command for the ui to streamlit run main.py --server.address 0.0.0.0 --server.port 80, this is due to how streamlit works.

The first time that you run the deploy command, you will be asked to login if you haven’t done it yet. You can also do it with the following command:

spai auth login

After running the deploy command, you will get a URL to your dashboard where you can track the status of your project as well as get public URLs for your APIs, UIs and notebooks and access to the logs.

As you can see, you don’t have to worry about setting up servers, databases, or any other infrastructure. We take care of that for you, provisioning the necessary resources in the cloud and managing them for you. You can focus on writing your code and let us take care of the rest.

Manage your project

Once your project is deployed, you can manage it with the following commands:

  • Retrieve a list of your projects in the cloud:
spai list projects
  • Retrieve a list of the services in a project:
spai list services "project-name"
  • Retrieve the logs of a service:
spai logs "project-name" "service-type" "service-name"
  • Stop the project:
spai stop "project-name" 

Stopping a project will stop all the running services, but your data will still be stored in the cloud. You can restart the project with the deploy command.

  • Delete the project:
spai delete "project-name" 

Deleting a project will remove all the data stored in the cloud. This action is irreversible.

What’s next?

We have just scratched the surface of what you can do with SPAI.

Continue in this tutorial section to learn, for example, how to deploy a complete Water Quality or Forest Monitoring service that you can completely automate and monetize easily with SPAI.

If you prefer to dig deeper into the platform, you can check the reference section to learn more about the different components of the platform, including the CLI and the Python library to build your own applications.

Back to top