Field
*****

class psynet.field.ImmutableVarStore(data)

   Bases: "BaseVarStore", "dict"

class psynet.field.PythonClass(*args, **kwargs)

   Bases: "PythonObject"

   cache_ok = True

      Whether SQLAlchemy may cache compiled statements that use this
      type.

      SQLAlchemy 2 requires an explicit value. Serialization is
      deterministic for a given value, so statement caching is safe.

   property python_type

      Return the Python type object expected to be returned by
      instances of this type, if known.

      Basically, for those types which enforce a return type, or are
      known across the board to do such for all common DBAPIs (like
      "int" for example), will return that type.

      If a return type is not defined, raises "NotImplementedError".

      Note that any type also accommodates NULL in SQL which means you
      can also get back "None" from any type in practice.

class psynet.field.PythonObject(*args, **kwargs)

   Bases: "TypeDecorator"

   cache_ok = True

      Whether SQLAlchemy may cache compiled statements that use this
      type.

      SQLAlchemy 2 requires an explicit value. Serialization is
      deterministic for a given value, so statement caching is safe.

   impl

      alias of "String"

   process_bind_param(value, dialect)

      Serialize values before storing them in the database.

   process_literal_param(value, dialect)

      Receive a literal parameter value to be rendered inline within a
      statement.

      Note:

        This method is called during the **SQL compilation** phase of
        a statement, when rendering a SQL string. Unlike other SQL
        compilation methods, it is passed a specific Python value to
        be rendered as a string. However it should not be confused
        with the "_types.TypeDecorator.process_bind_param()" method,
        which is the more typical method that processes the actual
        value passed to a particular parameter at statement execution
        time.

      Custom subclasses of "_types.TypeDecorator" should override this
      method to provide custom behaviors for incoming data values that
      are in the special case of being rendered as literals.

      The returned string will be rendered into the output string.

   process_result_value(value, dialect)

      Deserialize values loaded from the database.

   property python_type

      Return the Python type object expected to be returned by
      instances of this type, if known.

      Basically, for those types which enforce a return type, or are
      known across the board to do such for all common DBAPIs (like
      "int" for example), will return that type.

      If a return type is not defined, raises "NotImplementedError".

      Note that any type also accommodates NULL in SQL which means you
      can also get back "None" from any type in practice.

class psynet.field.VarStore(owner)

   Bases: "BaseVarStore"

   A repository for arbitrary variables which will be serialized to
   JSON for storage into the database, specifically in the "details"
   field. Variables can be set with the following syntax:
   "participant.var.my_var_name = "value_to_set"". The variable can
   then be accessed with "participant.var.my_var_name". See the
   methods below for an alternative API.

   **TIP 1:** the standard setter function is unavailable in lambda
   functions, which are otherwise convenient to use when defining e.g.
   "CodeBlock" objects. Use "psynet.field.VarStore.set()" instead, for
   example:

      from psynet.timeline import CodeBlock

      CodeBlock(lambda participant: participant.var.set("my_var", 3))

   **TIP 2:** by convention, the "VarStore" object is placed in an
   object's "var" slot. You can add a "VarStore" object to a custom
   object (e.g. a Dallinger "Node") as follows:

      from dallinger.models import Node
      from psynet.field import VarStore

      class CustomNode(Node):
          __mapper_args__ = {"polymorphic_identity": "custom_node"}

          @property
          def var(self):
              return VarStore(self)

   **TIP 3:** avoid storing large objects here on account of the
   performance cost of converting to and from JSON.

psynet.field.claim_var(name, use_default=False, default=lambda : ..., serialise=lambda x: ..., unserialise=lambda x: ...)

   Create a property backed by "VarStore".

   Parameters:
      * **name** -- Variable name stored under "obj.var".

      * **use_default** -- If true, return "default()" when the
        variable is missing.

      * **default** -- Zero-argument callable used when "use_default"
        is true.

      * **serialise** -- Transform applied before writing to VarStore.

      * **unserialise** -- Transform applied after reading from
        VarStore.

   -[ Notes ]-

   Older code passed a second "extra_vars" dict ("claim_var("x",
   __extra_vars__)"). That argument is no longer accepted; passing a
   dict raises "TypeError" so missing vars are not silently turned
   into "use_default=True".
