baseplate.clients.cassandra

Cassandra is a database designed for high-availability, high write throughput, and eventual consistency.

Baseplate.py supports both the base Python Cassandra driver and the Cassandra ORM, CQLMapper.

Example

To integrate the Cassandra driver with your application, add the appropriate client declaration to your context configuration:

baseplate.configure_context(
   app_config,
   {
      ...
      "foo": CassandraClient("mykeyspace"),
      ...
   }
)

configure it in your application’s configuration file:

[app:main]

...

# required: a comma-delimited list of hosts to contact to find the ring
foo.contact_points = cassandra-01.local, cassandra-02.local

# optional: the port to connect to on each cassandra server
# (default: 9042)
foo.port = 9999

# optional: the name of a CredentialSecret holding credentials for
# authenticating to cassandra
foo.credential_secret = secret/my_service/cassandra-foo

...

and then use the attached Session-like object in request:

def my_method(request):
    request.foo.execute("SELECT 1;")

Configuration

class baseplate.clients.cassandra.CassandraClient(keyspace, **kwargs)[source]

Configure a Cassandra client.

This is meant to be used with baseplate.Baseplate.configure_context().

See cluster_from_config() for available configuration settings.

Parameters:keyspace (str) – Which keyspace to set as the default for operations.
class baseplate.clients.cassandra.CQLMapperClient(keyspace, **kwargs)[source]

Configure a CQLMapper client.

This is meant to be used with baseplate.Baseplate.configure_context().

See cluster_from_config() for available configuration settings.

Parameters:keyspace (str) – Which keyspace to set as the default for operations.
baseplate.clients.cassandra.cluster_from_config(app_config, secrets=None, prefix='cassandra.', execution_profiles=None, **kwargs)[source]

Make a Cluster from a configuration dictionary.

The keys useful to cluster_from_config() should be prefixed, e.g. cassandra.contact_points etc. The prefix argument specifies the prefix used to filter keys. Each key is mapped to a corresponding keyword argument on the Cluster constructor. Any keyword arguments given to this function will be passed through to the Cluster constructor. Keyword arguments take precedence over the configuration file.

Supported keys:

  • contact_points (required): comma delimited list of contact points to try connecting for cluster discovery
  • port: The server-side port to open connections to.
  • credentials_secret (optional): the key used to retrieve the database
    credentials from secrets as a CredentialSecret.
Parameters:execution_profiles (Optional[Dict[str, ExecutionProfile]]) – Configured execution profiles to provide to the rest of the application.
Return type:Cluster

Classes

class baseplate.clients.cassandra.CassandraContextFactory(session)[source]

Cassandra session context factory.

This factory will attach a proxy object which acts like a cassandra.cluster.Session to an attribute on the RequestContext. The execute(), execute_async() and prepare() methods will automatically record diagnostic information.

Parameters:session (cassandra.cluster.Session) – A configured session object.
class baseplate.clients.cassandra.CQLMapperContextFactory(session)[source]

CQLMapper ORM connection context factory.

This factory will attach a new CQLMapper cqlmapper.connection.Connection to an attribute on the RequestContext. This Connection object will use the same proxy object that CassandraContextFactory attaches to a context to run queries so the execute command will automatically record diagnostic information.

Parameters:session (cassandra.cluster.Session) – A configured session object.