> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tai42.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pooled clients (tai42_kit.clients)

> Pooled Postgres/Redis clients and connection settings.

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`

```python theme={null}
class ClientDisconnectedError(Exception)
```

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`

```python theme={null}
class ClientSettings(TaiBaseSettings)
```

**Attributes**

| Attribute          | Type   |
| ------------------ | ------ |
| `registry_exclude` | `bool` |

### Members

#### client\_kwargs

`tai42_kit.clients.settings.ClientSettings.client_kwargs`

```python theme={null}
client_kwargs(self) -> dict[str, Any]
```

Connection kwargs passed to the client's `_create` / `current`.

## PooledClient

`tai42_kit.clients.base.PooledClient`

```python theme={null}
class PooledClient
```

### Members

#### current

`tai42_kit.clients.base.PooledClient.current`

```python theme={null}
async current(self, **kwargs) -> AsyncIterator[T]
```

**Parameters**

| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| `kwargs`  | —    | `{}`    | —           |

#### close

`tai42_kit.clients.base.PooledClient.close`

```python theme={null}
async close(self, **kwargs) -> None
```

**Parameters**

| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| `kwargs`  | —    | `{}`    | —           |

## PostgresConnectionSettings

`tai42_kit.clients.settings.PostgresConnectionSettings`

```python theme={null}
class PostgresConnectionSettings(ClientSettings)
```

**Attributes**

| Attribute                      | Type        |
| ------------------------------ | ----------- |
| `registry_exclude`             | `bool`      |
| `pg_host`                      | `str`       |
| `pg_port`                      | `int`       |
| `pg_db`                        | `str`       |
| `pg_user`                      | `str`       |
| `pg_password`                  | `SecretStr` |
| `pg_min_connections`           | `int`       |
| `pg_max_connections`           | `int`       |
| `pg_connect_timeout`           | `int`       |
| `pg_statement_timeout_seconds` | `float`     |
| `pg_dsn` *(property)*          | `str`       |

### Members

#### client\_kwargs

`tai42_kit.clients.settings.PostgresConnectionSettings.client_kwargs`

```python theme={null}
client_kwargs(self) -> dict[str, Any]
```

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`

```python theme={null}
class RedisConnectionSettings(ClientSettings)
```

**Attributes**

| Attribute                | Type            |
| ------------------------ | --------------- |
| `registry_exclude`       | `bool`          |
| `redis_url`              | `str \| None`   |
| `redis_max_connections`  | `int \| None`   |
| `decode_responses`       | `bool`          |
| `socket_timeout`         | `float \| None` |
| `socket_connect_timeout` | `float \| None` |
| `retry_on_timeout`       | `bool`          |
| `retry_attempts`         | `int`           |

### Members

#### client\_kwargs

`tai42_kit.clients.settings.RedisConnectionSettings.client_kwargs`

```python theme={null}
client_kwargs(self) -> dict[str, Any]
```

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.

## client\_ctx

`tai42_kit.clients.facade.client_ctx`

```python theme={null}
client_ctx(
    client_cls: type[PooledClient[T]],
    settings: ClientSettings | None = None,
    *,
    fresh: bool = False,
    **kwargs: Any,
) -> AbstractAsyncContextManager[T]
```

**Parameters**

| Parameter    | Type                     | Default | Description |
| ------------ | ------------------------ | ------- | ----------- |
| `client_cls` | `type[PooledClient[T]]`  | —       | —           |
| `settings`   | `ClientSettings \| None` | `None`  | —           |
| `fresh`      | `bool`                   | `False` | —           |
| `kwargs`     | `Any`                    | `{}`    | —           |

## shutdown\_all\_clients

`tai42_kit.clients.base.shutdown_all_clients`

```python theme={null}
async shutdown_all_clients() -> None
```

Close every live client pool for the running event loop.

Sweeps the per-loop class-keyed cache and closes each pooled client. Closes
are best-effort — failures are collected and raised together, never silently
dropped.
