Eruption Python 3 SDK
This is the documentation of the Python 3 SDK for Eruption
Table of Contents
Using the Python SDK
Getting started
First you need to set up the required environment:
- Create a virtual environment (venv)
- Install the dependencies
- Eruption Python 3 SDK
- Google Protocol Buffers
- Run an example application to test the installation
simple.pylocated insdk/examples/python/
Installation Instructions
Create the virtual environment (venv)
python3 -m venv venv
source venv/bin/activate
Now install the dependencies
pip install eruption-sdk
Example Code
Imports
from eruption import SDK_VERSION, Connection, Canvas, Color
Establishing a Connection
The 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 Profiles
The current active profile file can be queried using get_active_profile() and set using switch_profile().
print("Currently using", connection.get_active_profile())
# Use the profile's full file path
connection.switch_profile("/var/lib/eruption/profiles/solid.profile")
Updating Parameters
One or more script parameters can be set using set_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 Canvas
Using the canvas with the Color class
# create a new canvas
canvas = 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 Connection
connection.disconnect()
print("Exiting now")
except (Exception) as e:
print(f"An error occurred: {type(e).__name__} {e}" )
Full Code Listing
import sys
import time
from eruption import SDK_VERSION, Connection, Canvas, Color
EXAMPLE_NAME = "Simple Python Example #1"
def main():
"""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 canvas
canvas = 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) as e:
print(f"An error occurred: {type(e).__name__} {e}" )
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
Metadata
Release files for eruption-sdk 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| eruption_sdk-0.0.10.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| eruption_sdk-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / eruption_sdk-0.0.10.tar.gz
| Download URL | eruption_sdk-0.0.10.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10a5868b8fa4738062d3946a1c03c691464acd328aaa34020d8328e649841f0c
|
|
BLAKE2b-256 checksum How to use checksums |
98128c93ecece36d8be2d2993e84dfb507fbca926087da456c1b58389129fc8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / eruption_sdk-0.0.10-py3-none-any.whl
| Download URL | eruption_sdk-0.0.10-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20c5451a320d8fdb020ef1b0f1852e598c620bccc917445e4c4f32202d78a5e1
|
|
BLAKE2b-256 checksum How to use checksums |
1efe42526a279033df07c68d5cd3052f26b694df24fd6f7cc151b93f48ef0e1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|