Properties

Create type-checked database properties in Models.

Example:

# people.py

from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()


class Knows(Relationship):

    label = "knows"

    timestamp = DateTime(default=current_datetime, nullable=False)

String

class bulbs.property.String(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of unicode

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Integer

class bulbs.property.Integer(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of int

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Long

class bulbs.property.Long(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of long

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Float

class bulbs.property.Float(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of float

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Null

class bulbs.property.Null(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type = None

Python type

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

List

class bulbs.property.List(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of list

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Dictionary

class bulbs.property.Dictionary(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of dict

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

DateTime

class bulbs.property.DateTime(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]
Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed (bool) – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

python_type

Python type

alias of datetime

coerce(key, value)

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_db(type_system, key, value)

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

validate(key, value)

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

Property

Property is the parent, abstract base class for all the Property classes above.

Use it to create new Property datatypes.

class bulbs.property.Property(fget=None, name=None, default=None, nullable=True, unique=False, indexed=False)[source]

Abstract base class for database property types used in Models.

Parameters:
  • fget (str) – Method name that returns a calculated value. Defaults to None.
  • name (str) – Database property name. Defaults to the Property key.
  • default (str, int, long, float, list, dict, or Callable) – Default property value. Defaults to None.
  • nullable (bool) – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.
Variables:
  • fget – Name of the method that gets the calculated Property value.
  • name – Database property name. Defaults to the Property key.
  • default – Default property value. Defaults to None.
  • nullable – If True, the Property can be null. Defaults to True.
  • indexed – If True, index the Property in the DB. Defaults to False.

Note

If no Properties have index=True, all Properties are indexed.

validate(key, value)[source]

Validates the Property value before saving it to the database.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

None

convert_to_db(type_system, key, value)[source]

Converts a Property value from its Python type to its database representation.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

convert_to_python(type_system, key, value)[source]

Converts a Property value from its database representation to its Python type.

Parameters:
  • type_system (TypeSystem) – TypeSystem object.
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object

coerce(key, value)[source]

Coerces a Property value to its Python type.

Parameters:
  • key (str) – Property key.
  • value (object) – Property value.
Return type:

object