Quickstart for SDK and Command Line Interface

Installation

Install via pip:

$ pip install galileo-sdk

or if you have the code checked out locally:

$ python setup.py install

Writing your first script

GalileoSdk takes in 5 optional parameters.

from galileo_sdk import GalileoSdk

# all parameters are optional however, must provide either auth and refresh token
# OR username and password
galileo = GalileoSdk(
    auth_token="AUTH_TOKEN", # optional, must also provide refresh token
    refresh_token="REFRESH_TOKEN",
    username="user@galileoapp.io", # optional, must also provide a password
    password="*****",
)
Alternatively, you can set the environment variables instead of passing in the parameters:
  • GALILEO_TOKEN

  • GALILEO_REFRESH_TOKEN

  • GALILEO_USER

  • GALILEO_PASSWORD

  • GALILEO_CONFIG

An example of exporting your environment variable on MacOS:

$ export GALILEO_USER=user@galileoapp.io

The most convenient and secure method for authentication is to use our AuthSdk helper class.

from galileo_sdk import GalileoSdk, AuthSdk

myauth = AuthSdk()
# On your first time using the sdk, this will open a web browser and ask you to sign in,
# or if you are in a headless environment, it will print an activation link to visit.
access_token, refresh_token, expiry_time = myauth.initialize()
galileo = GalileoSdk(auth_token=access_token, refresh_token=refresh_token)

GalileoSdk exposes the Jobs, Machines, Profiles, Projects, and Stations APIs

Examples of using each of the APIs:

from galileo_sdk import GalileoSdk

galileo = GalileoSdk()
jobs = galileo.jobs.list_jobs()
stations = galileo.stations.list_stations()
users = galileo.profiles.list_users()
machines = galileo.machines.list_machines()
project = galileo.projects.create_project()

You can also write callbacks that will execute upon events. The example below is a script that allows an admin of stations to automatically accept all requests to join a station:

from galileo_sdk import GalileoSdk

galileo = GalileoSdk()

# An event of type StationAdminRequestReceivedEvent is passed in to your
# callback upon the trigger of a "on_station_admin_request_received" event.
# This allows you to know who requested to join and what station they requested to join.
def on_request_received(event: StationAdminRequestReceivedEvent):
    stationid = event["stationid"]
    userid = event["userid"]
    approve_request_to_join(stationid, [userid])

galileo.station.on_station_admin_request_received(on_request_received)

Before you end your script, you must disconnect the Galileo object via:

galileo.disconnect()