Scripting
Gaia Sky exposes an API that can be accessed through Python (see below), via an HTTP server, and using the in-app console. In this section we focus on the Python method. The API can be called from Python programs, that must be run with the system Python interpreter. They connect to a server created by a running instance of Gaia Sky.
Installing the environment
In order to connect to Gaia Sky from your Python scripts, you need to set up the environment. There are two main steps:
Install Python. Any reasonably up-to-date version of Python 3 should do.
Install the
py4j
package. We recommend usingpipenv
, or any other virtual environment manager. You can installpipenv
for your user withpip install --user pipenv
.
$ pipenv install py4j
Alternatively, you may use your distribution or operating system package manager to install py4j
. Please, refer to its documentation for more information.
Here are the Py4J homepage and the Pipenv homepage.
Running a test script
Once Python and py4j
are ready, launch Gaia Sky, download this script, open a terminal window (PowerShell in Windows) and run:
$ # If you used pipenv, enter the virtual environment
$ pipenv shell
$ # Run the script
$ python get-cam-state.py
If all goes well, the script should print some information it got from Gaia Sky about the camera. This means that your environment is ready to use.
Debugging
To debug a script in the terminal you can use the module pudb
. Once installed, run this:
$ python -m pudb gaiasky-script.py
Please refer to the pudb documentation for more information.
API versions
As of Gaia Sky 3.6.9, we have two API versions: APIv2 and APIv1. If you are starting with Gaia Sky scripting, we strongly recommend using the newer APIv2. The old APIv1 will be kept around for backwards compatibility. We’ll still fix bugs, but it won’t be extended and developed further.