Bases: ValueError

InvalidDefinitionError class

class*args, **kwargs)[source]

Bases: SQLMixinDallinger

We apply this mixin when creating our own SQL-backed classes from scratch. For example:

from import SQLBase, SQLMixin, register_table

class Bird(SQLBase, SQLMixin):
    __tablename__ = "bird"

class Sparrow(Bird):
class*args, **kwargs)[source]

Bases: SharedMixin

We apply this Mixin class when subclassing Dallinger classes, for example Network and Info. It adds a few useful exporting features, but most importantly it adds automatic mapping logic, so that polymorphic identities are constructed automatically from class names instead of having to be specified manually. For example:

from dallinger.models import Info

class CustomInfo(Info)

Removes personally identifying information from the object’s JSON representation. This is a destructive operation (it changes the input object).


Determines the information that is shown for this object in the dashboard and in the csv files generated by psynet export.[source]

Drops all tables from the Postgres database. Includes a workaround for the fact that SQLAlchemy doesn’t provide a CASCADE option to drop_all, which was causing errors with Dallinger’s version of database resetting in init_db.

(, scrub_pii)[source]

Exports all database objects to JSON-style dictionaries and writes them to CSV files, one for each class type.

  • dir – Directory to which the CSV files should be exported.

  • scrub_pii (bool) – Whether to remove personally identifying information.[source]

Lists the tables in the database.


  • A dictionary where the keys identify the tables and the values are the table objects themselves.[source]

Return the SQLAlchemy base class of an object x, returning None if no such base class is found., model, engine=None, clear_columns=None, replace_columns=None)[source]

Imports a CSV file to the database. The implementation is similar to, but incorporates a few extra parameters (clear_columns, replace_columns) and does not fail for tables without an id column.

  • file – CSV file to import (specified as a file handler, created for example by open())

  • model – SQLAlchemy class corresponding to the objects that should be created.

  • clear_columns (Optional[List]) – Optional list of columns to clear when importing the CSV file. This is useful in the case of foreign-key constraints (e.g. participant IDs).

  • replace_columns (Optional[dict]) – Optional dictionary of values to set for particular columns., engine=None)[source]

Given a path to a zip file created with export(), recreate the database with the data stored in the included .csv files. This is a patched version of that incorporates support for custom tables.[source]

This decorator should be applied whenever defining a new SQLAlchemy table. For example:

class Bird(SQLBase, SQLMixin):
    __tablename__ = "bird"[source]

Lists the base classes underpinning the different SQL tables used by PsyNet, including both base classes defined in Dallinger (e.g. Node, Info) and additional classes defined in custom PsyNet tables.


  • A dictionary of base classes (e.g. Node), keyed by the corresponding

  • table names for those base classes (e.g. node).[source]

Determines the list of objects in the dashboard database browser.