Skip to main content

Writing scripts

Since the behaviour of the Pioreactor is controlled by Python objects, you can write Python scripts that use those objects. Here's a simple example of starting the stirring by creating the Stirrer object:

from pioreactor.background_jobs.stirring import Stirrer, RpmFromFrequency
from pioreactor.whoami import get_unit_name
from pioreactor.whoami import get_latest_experiment_name

unit = get_unit_name()
experiment = get_latest_experiment_name()

st = Stirrer(


st.block_until_disconnected() # pauses the execution, but stirring continues

Save this code to a local file on your Pioreactor's Raspberry Pi called Then, running python, you should see that stirring on the Pioreactor starts. With the script running, you should also updates on the Pioreactor UI (ex: see pioreactor.local/pioreactors page). Typing ctrl-c will exit the script.


What is get_unit_name and get_latest_experiment_name? These are helper functions that get the current name of the Pioreactor, and the current experiment name, respectively. Using the current experiment name will ensure that your data shows up in the UI, and is correctly stored in the database.


Using automations requires you to invoke them with a Controller. For example, below we start a chemostat with some specific parameters, and set the target temperature to 30C.

from pioreactor.background_jobs.dosing_control import DosingController
from pioreactor.background_jobs.temperature_control import TemperatureController
from pioreactor.whoami import get_latest_experiment_name

unit = get_unit_name()
experiment = get_latest_experiment_name()

dc = DosingController(
"chemostat", # automation name
duration=1, # every minute,
volume=1, # dose 1mL

tc = TemperatureController(


Starting a long-running script

On the command line, you can run your script with


If you want to run the script in the background (so you can close terminal and the job continues in the background), use

python >/dev/null 2>&1 & disown

You can also use the Pioreactor's plugin architecture to control the start and stop of the script.

Useful utility objects

  • RepeatedTimer: this class allows you to scheduale a function to run every N seconds in a non-blocking manner.