cassandra.cqlengine.columns - Column types for object mapping models

Columns

Columns in your models map to columns in your CQL table. You define CQL columns by defining column attributes on your model classes. For a model to be valid it needs at least one primary key column and one non-primary key column.

Just as in CQL, the order you define your columns in is important, and is the same order they are defined in on a model’s corresponding table.

Each column on your model definitions needs to be an instance of a Column class.

class cassandra.cqlengine.columns.Column(**kwargs)[source]
primary_key = False

bool flag, indicates this column is a primary key. The first primary key defined on a model is the partition key (unless partition keys are set), all others are cluster keys

partition_key = False

indicates that this column should be the partition key, defining more than one partition key column creates a compound partition key

index = False

bool flag, indicates an index should be created for this column

db_field = None

the fieldname this field will map to in the database

default = None

the default value, can be a value or a callable (no args)

required = False

boolean, is the field required? Model validation will raise and exception if required is set to True and there is a None value assigned

clustering_order = None

only applicable on clustering keys (primary keys that are not partition keys) determines the order that the clustering keys are sorted on disk

polymorphic_key = False

Deprecated

see discriminator_column

discriminator_column = False

boolean, if set to True, this column will be used for discriminating records of inherited models.

Should only be set on a column of an abstract model being used for inheritance.

There may only be one discriminator column per model. See __discriminator_value__ for how to specify the value of this column on specialized models.

static = False

boolean, if set to True, this is a static column, with a single value per partition

Column Types

Columns of all types are initialized by passing Column attributes to the constructor by keyword.

class cassandra.cqlengine.columns.Ascii(**kwargs)[source]

Stores a US-ASCII character string

class cassandra.cqlengine.columns.BigInt(**kwargs)[source]

Stores a 64-bit signed long value

class cassandra.cqlengine.columns.Blob(**kwargs)[source]

Stores a raw binary value

cassandra.cqlengine.columns.Bytes

alias of Blob

class cassandra.cqlengine.columns.Boolean(**kwargs)[source]

Stores a boolean True or False value

class cassandra.cqlengine.columns.Counter(index=False, db_field=None, required=False)[source]

Stores a counter that can be inremented and decremented

class cassandra.cqlengine.columns.Date(**kwargs)[source]

Note: this type is overloaded, and will likely be changed or removed to accommodate distinct date type in a future version

Stores a date value, with no time-of-day

class cassandra.cqlengine.columns.DateTime(**kwargs)[source]

Stores a datetime value

class cassandra.cqlengine.columns.Decimal(**kwargs)[source]

Stores a variable precision decimal value

class cassandra.cqlengine.columns.Float(double_precision=True, **kwargs)[source]

Stores a floating point value

class cassandra.cqlengine.columns.Integer(**kwargs)[source]

Stores a 32-bit signed integer value

class cassandra.cqlengine.columns.List(value_type, default=<type 'list'>, **kwargs)[source]

Stores a list of ordered values

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_list_t.html

Parameters:value_type – a column class indicating the types of the value
class cassandra.cqlengine.columns.Map(key_type, value_type, default=<type 'dict'>, **kwargs)[source]

Stores a key -> value map (dictionary)

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_map_t.html

Parameters:
  • key_type – a column class indicating the types of the key
  • value_type – a column class indicating the types of the value
class cassandra.cqlengine.columns.Set(value_type, strict=True, default=<type 'set'>, **kwargs)[source]

Stores a set of unordered, unique values

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_set_t.html

Parameters:
  • value_type – a column class indicating the types of the value
  • strict – sets whether non set values will be coerced to set type on validation, or raise a validation error, defaults to True
class cassandra.cqlengine.columns.Text(min_length=None, max_length=None, **kwargs)[source]

Stores a UTF-8 encoded string

Parameters:
  • min_length (int) – Sets the minimum length of this string, for validation purposes. Defaults to 1 if this is a required column. Otherwise, None.
  • max_lemgth (int) – Sets the maximum length of this string, for validation purposes.
class cassandra.cqlengine.columns.TimeUUID(**kwargs)[source]

UUID containing timestamp

class cassandra.cqlengine.columns.UserDefinedType(user_type, **kwargs)[source]

User Defined Type column

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/cqlUseUDT.html

These columns are represented by a specialization of cassandra.cqlengine.usertype.UserType.

Please see User Defined Types for examples and discussion.

Parameters:user_type (type) – specifies the UserType model of the column
class cassandra.cqlengine.columns.UUID(**kwargs)[source]

Stores a type 1 or 4 UUID

class cassandra.cqlengine.columns.VarInt(**kwargs)[source]

Stores an arbitrary-precision integer