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

kill_task()
load(path)

Load board data from filesystem

Variables:
  • board_path (str) – Path of the board
  • data (dict) – data object that contains all board info
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'
enabled_behaviorports

Get and set the experiment name

Return type:list(Boolean)
enabled_bncports

Get and set enabled bncports

Return type:list(Boolean)
enabled_wiredports

Get and set the enabled wired ports

Return type:list(Boolean)
name

Get and set the board name

Return type:str
net_port

Get and set the experiment name

Return type:list(Boolean)
path

Get and set the board path

Return type:str
project

Get and set the board project

Return type:str
serial_port

Get and set the board serial port

Return type:str
status

Get and set the board status

Return type:str

models.experiment

Overview

Enumerates Bpod experiment supported operations.

Implementation

class pybpodgui_api.models.experiment.Experiment(project)[source]
create_setup()

Create new instance of setup

Return type:Setup
load(path)

Load experiment data from filesystem

Variables:
  • experiment_path (str) – Path of the experiment
  • data (dict) – data object that contains all experiment info
Returns:

Dictionary with loaded experiment info.

remove()

Remove experiment

save()

Save experiment data on filesystem.

Variables:parent_path (dict) – Project path.
Returns:Dictionary containing the experiment info to save.
Return type:dict
name

Get and set the experiment name

Return type:str
path

Get and set the experiment files path

Return type:str
project

Get and set the experiment project

Return type:Project
setups

Get the experiment setups

Return type:list(Setup)
task

Get and set the experiment task

Return type:Task

models.project

Overview

Enumerates Bpod project supported operations.

Implementation

class pybpodgui_api.models.project.Project[source]
create_board()

Add an board to the project, and return it.

Return type:Board
create_experiment()

Add an experiment to the project, and return it.

Return type:Experiment
create_subject()

Add an subject to the project, and return it.

Return type:Subject
create_task()

Add an task to the project, and return it.

Return type:Task
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

boards

Get the list of boards in the project

Return type:list(Board)
experiments

Get the list of experiments in the project

Return type:list(Experiment)
name

Get and set the project name

Return type:str
path

Get and set the project path

Return type:str
subjects

Get the list of subjects in the project

Return type:list(Subject)
tasks

Get the list of tasks in the project

Return type:list(Task)
users

Get the list of users in the project

Return type:list(User)

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
board_name

Get and set board name

Return type:str
board_serial_port

Get and set board serial port

Return type:str
ended

Get and set the end datetime of the session

Return type:datetime.datetime
filepath
is_running
messages_history

Get and set the history of messages

Return type:list(BaseMessage)
name

Get and set session name

Return type:str
path

Get and set path name

Return type:str
project

Get the session Project

Return type:Project
setup

Get and set the setup

Return type:Setup
setup_name

Get and set setup name

Return type:str
started

Get and set the start datetime of the session

Return type:datetime.datetime
status

Get and set the session status

Return type:str
subjects

Get and set session name

Return type:
task

Get the session Task

Return type:Task
task_name

Get and set the task name

Return type:str
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
load(data)[source]

Load setup data from filesystem

Variables:
  • setup_path (str) – Path of the setup
  • data (dict) – data object that contains all setup info
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
board

Get and set the board

Return type:Board
task

Get and set the Task

Return type:Task
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]
load(data)[source]

Load variable data from filesystem

Variables:data (dict) – data object that contains all task variable info
save()[source]

Save variable data on filesystem.

Variables:setup_path (str) – Setup path.
Returns:Dictionary containing the variable info to save.
Return type:dict
datatype

Get and set variable data type. It can be from type ‘number’ or ‘string’

Return type:str
name

Get and set variable name

Return type:str

Overview

Enumerates Bpod setup supported operations.

Implementation

class pybpodgui_api.models.setup.Setup(experiment)[source]
can_run_task()
clear_subjects()
create_board_task()

Create a new BoardTask object

Return type:BoardTask
create_session()

Create a new Session object

Return type:Session
kill_task()
load(path)

Load setup data from filesystem

Variables:
  • setup_path (str) – Path of the setup
  • data (dict) – data object that contains all setup info
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()
board

Get and set setup board

Return type:Board
detached
experiment

Get and set the experiment

Return type:Experiment
last_session

Get last created session

Return type:Session
name

Get and set setup name

Return type:str
net_port
path

Get and set setup path

Return type:str
project

Get project

Return type:Project
sessions

Get the list of sessions

Return type:list(Session)
status
subjects

Get list of subjects

Return type:list(Subject)
task

Get and set task

Return type:Task
update_variables

models.subject

Overview

Enumerates Bpod Subject supported operations.

Implementation

class pybpodgui_api.models.subject.Subject(project)[source]
can_run_task()
get_sessions()

Get all subject sessions

Return type:list(Session)
load(path)

Load subject data from filesystem

Variables:
  • subject_path (str) – Path of the subject
  • data (dict) – data object that contains all subject info
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()
name

Get and set setup name

Return type:str
path

Get and set the path

Return type:str
project

Get and set project

Return type:str
setup

Get and set project

Return type:str

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:
  • task_path (str) – Path of the task
  • data (dict) – data object that contains all task info
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:
  • project_path (str) – Project path.
  • data (dict) – Dictionary where to save the data to.
Returns:

Dictionary containing the task info to save.

Return type:

dict

commands

Get commands

Return type:list(TaskCommand)
filepath

Get and set task file path

Return type:str
name

Get and set task name

Return type:str
path

Get and set task path

Return type:str
project

Get and set project

Return type:Project
trigger_softcodes

Get net port

Return type:int

Project Info

The SWP Team

_images/fc_logo.jpg

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.