Skip to main content
Pooled clients + the generic client facade. Each client subclasses PooledClient (per-loop pooling, satisfies the contract BaseClient Protocol) and is reached by class through client_ctx. The driver each impl needs is declared by an extra (tai42-kit[curl] / [postgres]); import a driver submodule only when its driver is installed.

ClientDisconnectedError

tai42_contract.errors.ClientDisconnectedError
Raised when a client disconnects unexpectedly and is removed from the cache. This is not a permanent failure — retrying the operation will cause a fresh client to be created automatically.

ClientSettings

tai42_kit.clients.settings.ClientSettings
Base a client’s settings subclass extends to supply connection kwargs via client_kwargs(). Attributes

Members

client_kwargs

tai42_kit.clients.settings.ClientSettings.client_kwargs
Connection kwargs passed to the client’s _create / current.

PooledClient

tai42_kit.clients.base.PooledClient
A per-event-loop, per-epoch pool for a single driver client of type T. Subclasses implement _create and _close; callers lease the shared client through current, which rebuilds it after a classified disconnection.

Members

current

tai42_kit.clients.base.PooledClient.current
Lease the pooled client for kwargs, creating it on first use. A disconnection inside the body evicts and closes the client and raises ClientDisconnectedError; retry to rebuild it. Parameters

close

tai42_kit.clients.base.PooledClient.close
Close and drop the pooled client for kwargs in the current epoch, if one is pooled. Parameters

PostgresConnectionSettings

tai42_kit.clients.settings.PostgresConnectionSettings
Base Postgres connection settings loaded under a database’s TAI_DATABASE_<NAME>_ prefix. Attributes

Members

pg_dsn

tai42_kit.clients.settings.PostgresConnectionSettings.pg_dsn
Build the libpq DSN from the connection fields; a missing host or password raises a named error.

client_kwargs

tai42_kit.clients.settings.PostgresConnectionSettings.client_kwargs
Connection identity for the pooled client — JSON-serializable only. Pools are keyed by DSN + min/max size; callers that disagree on pool bounds get separate pools.

RedisConnectionSettings

tai42_kit.clients.settings.RedisConnectionSettings
Base Redis connection settings with unprefixed field names for a store to subclass with its own prefix. Attributes

Members

client_kwargs

tai42_kit.clients.settings.RedisConnectionSettings.client_kwargs
Connection identity for the pooled client — JSON-serializable only. The facade keys its per-loop connection pool on these kwargs, so every value must be JSON-serializable. retry_attempts travels as an int; the redis client turns it into a Retry object at construction time — a Retry instance is not serializable and would break the pool key. env_prefix rides along so the client can name this store’s own env var when redis_url is unset; it is not connection identity, so the redis client drops it from the pool key.

advance_client_epoch

tai42_kit.clients.base.advance_client_epoch
Advance the process-wide client epoch and return the epoch just retired. New current() leases pool under the new epoch; the retired epoch’s pools stay live until their last lease releases (or drain_epoch force-closes them at a deadline). The same counter stamps cached settings instances.

client_ctx

tai42_kit.clients.facade.client_ctx
Return an async context manager yielding a connected client for client_cls. Pass either settings (its client_kwargs() supplies the connection kwargs) or raw **kwargs, never both. fresh=True builds a one-shot client outside the pool and closes it on exit; otherwise the client is pooled and reused per event-loop + connection params. Parameters

current_client_epoch

tai42_kit.clients.base.current_client_epoch
The current client epoch — the value new leases and settings stamps carry.

drain_epoch

tai42_kit.clients.base.drain_epoch
Drain and close a retired epoch’s client pools for the running loop. Waits up to deadline seconds for every leased client of epoch to reach zero leases (each closes itself on its last release), then force-closes any that remain regardless of held leases, collecting failures into an ExceptionGroup so none is dropped. Must run on the loop that owns the pools; the current epoch cannot be drained. Parameters

shutdown_all_clients

tai42_kit.clients.base.shutdown_all_clients
Close every live client pool for the running event loop. Sweeps every epoch of the per-loop class-keyed cache and closes each pooled client — process-teardown semantics, independent of leases. Closes are best-effort — failures are collected and raised together, never silently dropped.