Welcome to PyBpod GUI API’s documentation!¶
This API makes available a set of functions and properties to allow the manipulation of a PyBpod GUI project using code.
Check the Examples section to learn how to use the API.
Examples¶
Create a new project¶
Create a new project programmatically. The resulting project can be opened with the PyBpod GUI.
from pybpodgui_api.models.project import Project
# create the project
proj = Project()
proj.name = 'First project'
# add an experiment to the project
exp = proj.create_experiment()
exp.name = 'First experiment'
# add a setup to the project
stp = exp.create_setup()
stp.name = 'First setup'
# add a board to the project
board = proj.create_board()
board.name = 'First board'
board.serial_port = 'COM3'
# add a subject to the project
subj = proj.create_subject()
subj.name = 'First animal'
# add a new task\protocol to the project
task = proj.create_task()
task.name = 'First task'
exp.task = task # set the task\protocol to the experiment
stp.board = board # set the board to the setup
stp += subj # add a subject to the setup
proj.save('my-project-folder')
task.code = 'print("My first protocol")'
proj.save(proj.path)
Access to data from a session¶
The next examples shows how to access the messages in a pybpod session.
from pybpodgui_api.models.project import Project
# create the project
proj = Project()
proj.load('my-project-folder')
exp = proj.experiments[0]
stp = exp.setups[0]
for session in stp.sessions:
for msg in session.messages_history:
if msg.check_type('INFO'):
pass
#Do somehting
elif msg.check_type('stderr'):
pass
#Do something
API Models
¶
models.board
¶
Overview¶
Enumerates Bpod board supported operations.
Implementation¶
-
class
pybpodgui_api.models.board.
Board
(project)[source]¶ -
end_run_task_handler
()¶
-
freegui
()¶ Function used to release the processing to update the GUI events
-
load
(path)¶ Load board data from filesystem
Variables:
-
log2board
(data)¶ Function used to update the board log
-
pause_trial
()¶
-
remove
()¶
-
resume_trial
()¶
-
run_task_handler
(flag=True)¶
-
save
()¶ Save experiment data on filesystem.
Variables: parent_path (dict) – Project path. Returns: Dictionary containing the board info to save. If None is returned, it means that ther was a failure. Return type: dict
-
start_run_task_handler
()¶
-
stop_task
()¶
-
stop_thread
()¶
-
stop_trial
()¶
-
INFO_BOARD_NAME
= 'BOARD-NAME'¶
-
INFO_BPODGUI_VERSION
= 'BPOD-GUI-VERSION'¶
-
INFO_CREATOR_NAME
= 'CREATOR-NAME'¶
-
INFO_EXPERIMENT_NAME
= 'EXPERIMENT-NAME'¶
-
INFO_PROJECT_NAME
= 'PROJECT-NAME'¶
-
INFO_SETUP_NAME
= 'SETUP-NAME'¶
-
INFO_SUBJECT_NAME
= 'SUBJECT-NAME'¶
-
models.experiment
¶
Overview¶
Enumerates Bpod experiment supported operations.
Implementation¶
-
class
pybpodgui_api.models.experiment.
Experiment
(project)[source]¶ -
-
load
(path)¶ Load experiment data from filesystem
Variables: Returns: Dictionary with loaded experiment info.
-
remove
()¶ Remove experiment
-
models.project
¶
Overview¶
Enumerates Bpod project supported operations.
Implementation¶
-
class
pybpodgui_api.models.project.
Project
[source]¶ -
-
create_experiment
()¶ Add an experiment to the project, and return it.
Return type: Experiment
-
create_user
()¶ Add a user bject to the project, and return it.
Return type: User
-
find_board
(name)¶ Find a board by the name
Variables: name (str) – Name of the board to find. Return type: Board
-
find_session
(uuid4)¶
-
find_setup_by_id
(uuid4)¶ Find a setup by the id
Variables: uuid4 (str) – UUID4 of the setup to find. Return type: Setup
-
find_subject
(name)¶ Find a subject by the name
Variables: name (str) – Name of the subject to find. Return type: Subject
-
find_subject_by_id
(uuid4)¶ Find a subject by the name
Variables: name (str) – Name of the subject to find. Return type: Subject
-
find_task
(name)¶ Find a task by the name
Variables: name (str) – Name of the task to find. Return type: Task
-
find_user
(username)¶
-
import_task
(filepath, importdir=False)¶
-
is_saved
()¶ Verifies if project has changes by doing a recursive checksum on all entities
Return type: bool
-
load
(project_path)¶ Load project from a folder.
Variables: project_path (str) – Full path of the project to load.
-
remove_non_existing_repositories
(path, names)¶
-
save
(project_path)¶ Save project data on file :param str project_path: path to project :return: project data saved on settings file
-
experiments
¶ Get the list of experiments in the project
Return type: list(Experiment)
-
models.session
¶
Overview¶
Enumerates Bpod session supported operations.
Implementation¶
-
class
pybpodgui_api.models.session.
Session
(setup)[source]¶ -
load
(path)¶ Parameters: - session_path –
- data –
Returns:
-
load_contents
(init_func=None, update_func=None, end_func=None)¶ Parses session history file, line by line and populates the history message on memory.
-
load_info
()¶
-
remove
()¶ Remove the session from the project
-
save
()¶ Parameters: parent_path – Returns:
-
STATUS_READY
= 0¶
-
STATUS_SESSION_RUNNING
= 1¶
-
ended
¶ Get and set the end datetime of the session
Return type: datetime.datetime
-
filepath
¶
-
is_running
¶
-
started
¶ Get and set the start datetime of the session
Return type: datetime.datetime
-
subjects
¶ Get and set session name
Return type:
-
variables
¶
-
models.setup
¶
models.board.board_task
¶
Overview¶
Enumerates Bpod BoardTask supported operations.
Implementation¶
-
class
pybpodgui_api.models.setup.board_task.
BoardTask
(setup)[source]¶ Represents the association between one board and one task
Variables: setup (Setup) – Setup to which the BoardTask belongs to -
create_variable
(name=None, value=None, datatype='string')[source]¶ Create a variable
Return type: TaskVariable
-
save
()[source]¶ Save board task data on filesystem.
Variables: setup_path (str) – Setup path. Returns: Dictionary containing the board task info to save. Return type: dict
-
update_variables
¶ Get and set a flag that indicates if the variables should be updated at the end of the session
Return type: bool
-
variables
¶ Get and set list of variables
Return type: list(TaskVariable)
-
models.board.taskvariable
¶
Overview¶
Enumerates Bpod task variable supported operations.
Implementation¶
-
class
pybpodgui_api.models.setup.task_variable.
TaskVariable
(board_task, name=None, value=None, datatype='string')[source]¶
Overview¶
Enumerates Bpod setup supported operations.
Implementation¶
-
class
pybpodgui_api.models.setup.
Setup
(experiment)[source]¶ -
can_run_task
()¶
-
clear_subjects
()¶
-
load
(path)¶ Load setup data from filesystem
Variables:
-
pause_trial
()¶
-
remove
()¶ Remove the setup from the project
-
resume_trial
()¶
-
save
()¶ Save setup data on filesystem.
Variables: parent_path (str) – Experiment path. Returns: Dictionary containing the setup info to save. Return type: dict
-
stop_task
()¶
-
stop_trial
()¶
-
detached
¶
-
experiment
¶ Get and set the experiment
Return type: Experiment
-
net_port
¶
-
status
¶
-
update_variables
¶
-
models.subject
¶
Overview¶
Enumerates Bpod Subject supported operations.
Implementation¶
-
class
pybpodgui_api.models.subject.
Subject
(project)[source]¶ -
can_run_task
()¶
-
load
(path)¶ Load subject data from filesystem
Variables:
-
post_load
()¶
-
remove
()¶ Remove the subject from the project
-
run_task
()¶
-
save
()¶ Save subject data on filesystem.
Variables: project_path (str) – Project path. Returns: Dictionary containing the setup info to save. Return type: dict
-
toJSON
()¶
-
models.task
¶
Overview¶
Enumerates Bpod Task supported operations.
Implementation¶
-
class
pybpodgui_api.models.task.
Task
(project=None)[source]¶ -
create_execcmd
()¶
-
create_scriptcmd
()¶
-
load
(path)¶ Load setup data from filesystem
Variables:
-
make_emptyfile
()¶ Creates the task folder if does not exists and an empty code file
-
make_path
()¶ Creates the task folder
-
remove
()¶ Remove the task from the project.
-
save
()¶ Save setup data on filesystem.
Variables: Returns: Dictionary containing the task info to save.
Return type:
-
Project Info¶
The SWP Team¶

Scientific Software Platform (Champalimaud Foundation)
The Scientific Software Platform (SWP) from the Champalimaud Foundation provides technical know-how in software engineering and high quality software support for the Neuroscience and Cancer research community at the Champalimaud Foundation.
We typical work on computer vision / tracking, behavioral experiments, image registration and database management.
PyBpod project¶
PyBpod is a python port of the Bpod Matlab project.
All examples and Bpod’s state machine and communication logic were based on the original version made available by Josh Sanders (Sanworks).
License¶
This is Open Source software with a MIT license.
Maintenance team¶
The current and past members of the pybpodgui-api team.
- @cajomferro Carlos Mão de Ferro
- @JBauto João Baúto
- @UmSenhorQualquer Ricardo Ribeiro
- @MicBoucinha Luís Teixeira