Skip to content

cayu.storage.application

Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.

from cayu import ApplicationStores

The stores selected by open_application_stores and their resources.

The object owns every store it built and, for PostgreSQL, the shared connection pool. close() closes the stores and then the pool, each at most once; after a failed close, calling it again retries only what did not close. Cayu’s server does not close application stores; long-lived processes keep them for their lifetime, and tests or scripts close them explicitly.

ApplicationStores.__init__(*, backend: SessionStoreBackend, session_store: SessionStore, task_store: TaskStore | None, knowledge_store: KnowledgeStore | None, product_store: ProductOperationStore | None=None, model_policy_store: ModelPolicyStore | None=None, pool: Any | None=None, pool_max_size: int | None=None, task_admission_listener: bool=False) -> None
ApplicationStores.backend() -> SessionStoreBackend
ApplicationStores.session_store() -> SessionStore
ApplicationStores.task_store() -> TaskStore | None
ApplicationStores.knowledge_store() -> KnowledgeStore | None
ApplicationStores.product_store() -> ProductOperationStore | None

The maintained service’s product operation store, when requested.

ApplicationStores.model_policy_store() -> ModelPolicyStore | None
ApplicationStores.pool_max_size() -> int | None

Maximum pooled PostgreSQL connections shared by the stores, if any.

ApplicationStores.connection_budget() -> int

Most PostgreSQL connections these stores open (pool plus listener).

async ApplicationStores.close() -> None

Close the stores, then the shared pool.

Once everything closed, later calls do nothing. After a failure, a later call retries only the parts that did not close.

async ApplicationStores.__aenter__() -> ApplicationStores
async ApplicationStores.__aexit__(*exc_info: object) -> None

Release source · Runtime guarantees · Capability guides

from cayu import open_application_stores

Build the application’s session, task, and knowledge stores.

database_url is normally configured_database_url(), the value of CAYU_DATABASE_URL. A postgres:// or postgresql:// URL builds the PostgreSQL stores on one shared connection pool of at most pool_max_size connections (default CAYU_DATABASE_POOL_MAX, else 5). They validate the schema at first use; migrations are an explicit deploy step (cayu storage migrate). The task store keeps one dedicated LISTEN connection outside the pool for task-admission wakeups. It connects to direct_database_url (default CAYU_DATABASE_DIRECT_URL, else database_url), because LISTEN does not survive transaction pooling.

None builds SQLite stores in sqlite_path, which must be absolute, with SQLite’s local-development schema behavior. An absolute sqlite:/// URL selects that file instead, matching the CLI’s store resolution. Any other URL scheme raises SessionStoreTargetError.

tasks and knowledge_scope choose which optional stores exist. product_operations=True adds the maintained service’s product operation store (it requires the server extra); on PostgreSQL it shares the pool, so the connection budget is unchanged. Nothing connects during construction.

open_application_stores(database_url: str | None, *, sqlite_path: str | os.PathLike[str], tasks: bool=True, knowledge_scope: KnowledgeAccessScope | None=None, product_operations: bool=False, model_policy: bool=False, public_authority_alias_codec: PublicAuthorityAliasCodec | None=None, pool_max_size: int | None=None, direct_database_url: str | None=None) -> ApplicationStores

Release source · Runtime guarantees · Capability guides