casdriv - Cassandra Driver Interface

Cassandra-Driver CRUD interface.

cassy.casdriv.connect_session(ips=('127.0.0.1',), port=9042, **kwargs)[source]

Connect and return session using fogd_db.casdb.

Parameters
Returns

Tuple of cassandra.session.Cluster and cassandra.session.Session as in ('cluster'=cluster, 'session'=session).

Return type

NamedTuple

cassy.casdriv.create_simple_keyspace(name, replication_factor, durable_writes=True, connections=None)[source]

Create a keyspace with SimpleStrategy for replica placement.

If the keyspace already exists, it will not be modified. Basically a very close wrapper of cassandra driver’s cqlengine functionality

Parameters
  • name (str) – name of keyspace to create

  • replication_factor (int) – keyspace replication factor, used with SimpleStrategy

  • durable_writes (bool, default=True) – Write log is bypassed if set to False.

  • connections (list) – List of connection names.

cassy.casdriv.create_entry(model, data, prior_syncing=False, keyspace=None, con=None)[source]

Create a new entry using a python data class model.

Parameters
  • model – One of the cassandra python-driver data class models.

  • data (dict) – Keyword value pairings of the data to be added. Most conform to the model used.

  • prior_syncing (bool, default=False) – If True synchronize_model() is called before creation, to synchronize database table and model. (Required if you call model.create for the first time, or change any model attributes.

  • keyspace (str, None, default=None) – String to specify the keyspace the table is created. If None, model.__keyspace__ is used.

  • con (str, None, default=None) –

    String to specify the connection name the table is created with. casdriv uses cluster name as default connection name.

    If None, model.__connection__ is used.

Returns

Instance of the model created using data.

Return type

model class

cassy.casdriv.delete_entry(model, primary_keys, values, keyspace=None, con=None)[source]

Delete an existing entry using a python data class model.

Parameters
  • model

    One of the cassandra python-driver data class models.

  • primary_keys (str, tuple) – String or tuple of strings specifying the label/schema of the primary key(s) to be read.

  • values (str, tuple) – String or tuple of strings specifying the value of the primary key to be queried for.

  • keyspace (str, None, default=None) – String to specify the keyspace the table is created. If None, model.__keyspace__ is used.

  • con (str, None, default=None) –

    String to specify the connection name the table is created with. casdriv uses cluster name as default connection name.

    If None, model.__connection__ is used.

cassy.casdriv.get_all_entries(model, keyspace=None, con=None)[source]

Get all entries of an existing data class model table.

Uses the cassandra python-driver queries

Parameters
  • model

    One of the cassandra python-driver data class models.

  • keyspace (str, None, default=None) – String to specify the keyspace the table is created. If None, model.__keyspace__ is used.

  • con (str, None, default=None) –

    String to specify the connection name the table is created with. casdriv uses cluster name as default connection name.

    If None, model.__connection__ is used.

Returns

List of table entries created via a cassandra python-driver data class models.

Return type

list

cassy.casdriv.get_cluster_name(cluster)[source]

Return clusters registered name.

Parameters

cluster (cassandra.cluster.Cluster) –

cassandra.cluster.Cluster object holding the cassandra database.

Returns

cluster.metadata.cluster_name

Return type

str

cassy.casdriv.list_keyspace_tables(cluster, keyspace)[source]

List all tables present in keyspaces.

Parameters
  • cluster (cassandra.cluster.Cluster) –

    cassandra.cluster.Cluster object holding the cassandra database.

  • keyspace (str) – String specifying the keyspace of the cluster of which all existing tables are to be listed

Returns

List of strings specifying the tables currently present inside the keyspace of cluster.

Return type

list

cassy.casdriv.list_cluster_keyspaces(cluster)[source]

List all keyspaces present in cluster.

Parameters

cluster (cassandra.cluster.Cluster) –

cassandra.cluster.Cluster object holding the cassandra database.

Returns

List of strings specifying the keyspaces currently present inside the cluster.

Return type

list

cassy.casdriv.list_table_primary_keys(cluster, keyspace, table)[source]

List all primary key labels (schemas?).

Parameters
  • cluster (cassandra.cluster.Cluster) –

    cassandra.cluster.Cluster object holding the cassandra database.

  • keyspace (str) – String specifying the keyspace of the cluster where table is to be found.

  • table (str) – String specifying the table inside the keyspace of cluster of which the primary key lable(s) is(are) to be listed.

Returns

List of strings specifying the found primary key lables

Return type

list

cassy.casdriv.list_table_columns(cluster, keyspace, table)[source]

List all primary key lables (schemas?).

Parameters
  • cluster (cassandra.cluster.Cluster) –

    cassandra.cluster.Cluster object holding the cassandra database.

  • keyspace (str) – String specifying the keyspace of the cluster where table is to be found.

  • table (str) – String specifying the table inside the keyspace of cluster of which the column labels are to be listed.

Returns

List of strings specifying the found column lables

Return type

list

cassy.casdriv.read_entry(model, primary_keys, values, keyspace=None, con=None)[source]

Read existing entry using a python data class model.

Uses the cassandra python-driver queries

Parameters
  • model

    One of the cassandra python-driver data class models.

  • primary_keys (str, tuple) – String or tuple of strings specifying the label/schema of the primary key(s) to be read.

  • values (str, tuple) – String or tuple of strings specifying the value of the primary key to be queried for.

  • keyspace (str, None, default=None) – String to specify the keyspace the table is created. If None, model.__keyspace__ is used.

  • con (str, None, default=None) –

    String to specify the connection name the table is created with. casdriv uses cluster name as default connection name.

    If None, model.__connection__ is used.

Returns

Instance of the model read.

Return type

model class

Raises

ValueError – Raised when primary_keys is neither of type tuple or str.

cassy.casdriv.synchronize_model(model)[source]

Synchronize the cassandra table with a python data class model.

Effectively creating a cassandra table out of a data class model, if not present.

Parameters

model

One of the cassandra python-driver data class models. Python data class model to synch.