Drivers

coodie uses a pluggable driver system. The driver registry manages connections to one or more Cassandra / ScyllaDB clusters.

Driver Registry

class coodie.drivers.AbstractDriver

Bases: ABC

Abstract base class for coodie execution backends.

needs_row_validation: bool = False
abstractmethod execute(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Execute stmt with params; return rows as a list of dicts.

abstractmethod sync_table(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Idempotent CREATE TABLE + ALTER TABLE ADD for new columns.

Returns the list of CQL statements that were (or would be) executed. When dry_run is True the database is not modified.

abstractmethod close() None

Release sync resources.

abstractmethod async execute_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Async version of execute().

abstractmethod async sync_table_async(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Async version of sync_table().

execute_one(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Execute stmt and return the first column of the first row, or None.

async execute_one_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Async version of execute_one().

abstractmethod async close_async() None

Release async resources.

class coodie.drivers.LazyDriver(hosts: list[str] | None, keyspace: str | None, ssl_context: SSLContext | None, kwargs: dict[str, Any])

Bases: AbstractDriver

Driver proxy that defers Cassandra/ScyllaDB connection until first use.

Created by init_coodie(..., lazy=True). The underlying CassandraDriver is instantiated on the first call to execute(), execute_async(), sync_table(), or sync_table_async().

execute(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Execute stmt with params; return rows as a list of dicts.

sync_table(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Idempotent CREATE TABLE + ALTER TABLE ADD for new columns.

Returns the list of CQL statements that were (or would be) executed. When dry_run is True the database is not modified.

close() None

Release sync resources.

async execute_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Async version of execute().

async sync_table_async(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Async version of sync_table().

async close_async() None

Release async resources.

coodie.drivers.register_driver(name: str, driver: AbstractDriver, default: bool = False) None
coodie.drivers.get_driver(name: str | None = None) AbstractDriver
coodie.drivers.init_coodie(hosts: list[str] | None = None, session: Any | None = None, keyspace: str | None = None, driver_type: str = 'scylla', name: str = 'default', ssl_context: SSLContext | None = None, lazy: bool = False, compression: str | bool | None = None, speculative_execution_policy: Any | None = None, **kwargs: Any) AbstractDriver
async coodie.drivers.init_coodie_async(hosts: list[str] | None = None, session: Any | None = None, keyspace: str | None = None, driver_type: str = 'scylla', name: str = 'default', ssl_context: SSLContext | None = None, ssl_enabled: bool | None = None, ssl_trusted_cert: str | None = None, ssl_cert: str | None = None, ssl_private_key: str | None = None, ssl_verify_flags: int | None = None, **kwargs: Any) AbstractDriver

Abstract Base Driver

class coodie.drivers.base.AbstractDriver

Bases: ABC

Abstract base class for coodie execution backends.

needs_row_validation: bool = False
abstractmethod execute(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Execute stmt with params; return rows as a list of dicts.

abstractmethod sync_table(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Idempotent CREATE TABLE + ALTER TABLE ADD for new columns.

Returns the list of CQL statements that were (or would be) executed. When dry_run is True the database is not modified.

abstractmethod close() None

Release sync resources.

abstractmethod async execute_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Async version of execute().

abstractmethod async sync_table_async(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Async version of sync_table().

execute_one(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Execute stmt and return the first column of the first row, or None.

async execute_one_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Async version of execute_one().

abstractmethod async close_async() None

Release async resources.

CassandraDriver (scylla-driver / cassandra-driver)

class coodie.drivers.cassandra.CassandraDriver(session: Any, default_keyspace: str | None = None)

Bases: AbstractDriver

Driver backed by cassandra-driver / scylla-driver.

execute(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Execute stmt with params; return rows as a list of dicts.

sync_table(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Idempotent CREATE TABLE + ALTER TABLE ADD for new columns.

Returns the list of CQL statements that were (or would be) executed. When dry_run is True the database is not modified.

execute_one(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Execute stmt and return the first column of the first row, or None.

async execute_one_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None) Any

Async version of execute_one().

close() None

Release sync resources.

async execute_async(stmt: str, params: list[Any], consistency: str | None = None, timeout: float | None = None, fetch_size: int | None = None, paging_state: bytes | None = None) list[dict[str, Any]]

Async version of execute().

async sync_table_async(table: str, keyspace: str, cols: list[Any], table_options: dict[str, Any] | None = None, dry_run: bool = False, drop_removed_indexes: bool = False) list[str]

Async version of sync_table().

async close_async() None

Release async resources.