Package: eruption-sdk
Eruption Python 3 SDKThis is the documentation of the Python 3 SDK for EruptionTable of ContentsEruption Python 3 SDKTable of ContentsUsing the Python SDKGetting startedInstallation InstructionsExample CodeImportsEstablishing a ConnectionSwitching ProfilesUpdating ParametersControlling the CanvasTerminating the ConnectionFull Code ListingUsing the Python SDKGetting startedFirst you need to set up the required environment:Create a virtual environment (venv)Install the dependenciesEruption Python 3 SDKGoogle Protocol BuffersRun an example application to test the installationsimple.pylocated insdk/examples/python/Installation InstructionsCreate the virtual environment (venv)python3-mvenvvenvsourcevenv/bin/activateNow install the dependenciespipinstalleruption-sdkExample CodeImportsfromeruptionimportSDK_VERSION,Connection,Canvas,ColorEstablishing a ConnectionThe following code will establish a connection to a running instance of Eruption via the
local transport (UNIX domain socket)# connect to the Eruption daemon (via a local connection)try:print("Connecting to the Eruption daemon...")connection=Connection(type=Connection.LOCAL)connection.connect()print("Successfully connected to the Eruption daemon")status=connection.get_server_status()print(status)Switching ProfilesThe current active profile file can be queried usingget_active_profile()and set usingswitch_profile().print("Currently using",connection.get_active_profile())# Use the profile's full file pathconnection.switch_profile("/var/lib/eruption/profiles/solid.profile")Updating ParametersOne or more script parameters can be set usingset_parameters().  Pass in the full file
path of the profile and the script, then any parameters you want to update.profile_file="/var/lib/eruption/profiles/solid.profile"script_file="/usr/share/eruption/scripts/solid.lua"connection.set_parameters(profile_file,script_file,color_background="#ff3f00ff",opacity=0.9)Controlling the CanvasUsing the canvas with the Color class# create a new canvascanvas=Canvas()red=Color(255,0,0,128)green=Color(0,255,0,128)blue=Color(0,0,255,128)final=Color(0,0,0,0)canvas.fill(red)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(green)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(blue)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(final)print("Submitting canvas...")connection.submit_canvas(canvas)Terminating the Connectionconnection.disconnect()print("Exiting now")except(Exception)ase:print(f"An error occurred:{type(e).__name__}{e}")Full Code ListingimportsysimporttimefromeruptionimportSDK_VERSION,Connection,Canvas,ColorEXAMPLE_NAME="Simple Python Example #1"defmain():"""Main program entrypoint"""print(f"Welcome to the Eruption SDK!\nYou are running the\"{EXAMPLE_NAME}\""f"from the Eruption SDK version{SDK_VERSION}\n")# connect to the Eruption daemon (via a local connection)try:print("Connecting to the Eruption daemon...")connection=Connection(type=Connection.LOCAL)connection.connect()print("Successfully connected to the Eruption daemon")status=connection.get_server_status()print(status)# create a new canvascanvas=Canvas()red=Color(255,0,0,128)green=Color(0,255,0,128)blue=Color(0,0,255,128)final=Color(0,0,0,0)canvas.fill(red)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(green)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(blue)print("Submitting canvas...")connection.submit_canvas(canvas)time.sleep(1)canvas.fill(final)print("Submitting canvas...")connection.submit_canvas(canvas)connection.disconnect()print("Exiting now")except(Exception)ase:print(f"An error occurred:{type(e).__name__}{e}")if__name__=="__main__":try:main()exceptKeyboardInterrupt:pass