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
ips¶ (Container) – Container holding contact_points to connect the cassandra.cluster.Cluster. Defaults to (“127.0.0.1”,), which is the local host.
port¶ (Number) – The server-side port to open connections to. Defaults to 9042.
kwargs¶ –
Additional arguments relegated to cassandra.cluster.Cluster
- Returns
Tuple of cassandra.session.Cluster and cassandra.session.Session as in
('cluster'=cluster, 'session'=session).- Return type
- 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
- 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
modelused.prior_syncing¶ (bool, default=False) – If
Truesynchronize_model()is called before creation, to synchronize database table and model. (Required if you callmodel.createfor 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.
casdrivusescluster nameas default connection name.If
None,model.__connection__is used.
- Returns
- 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.
casdrivusescluster nameas 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.
casdrivusescluster nameas 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
- 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
- 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
keyspaceofcluster.- Return type
- 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
- 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
clusterwheretableis to be found.table¶ (str) – String specifying the table inside the
keyspaceofclusterof which the primary key lable(s) is(are) to be listed.
- Returns
List of strings specifying the found primary key lables
- Return type
- 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
clusterwheretableis to be found.table¶ (str) – String specifying the table inside the
keyspaceofclusterof which the column labels are to be listed.
- Returns
List of strings specifying the found column lables
- Return type
- 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.
casdrivusescluster nameas default connection name.If
None,model.__connection__is used.
- Returns
Instance of the
modelread.- Return type
model class
- Raises
ValueError – Raised when
primary_keysis 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.