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

# alibi_sdk.plugins.kafka_plugin

> Kafka plugin — generated from python/alibi_sdk source.

Kafka plugin — topic/prefix isolation + produce/consume observation.

Default backend is an in-memory topic store (tests + demos without a broker).
Pass `client_factory` to wire a real producer/consumer later.

Install::

from alibi\_sdk.plugins import create\_kafka\_plugin
kafka = create\_kafka\_plugin(bootstrap\_servers="localhost:9092", topic\_prefix="alibi.")

*Source:* [`python/alibi_sdk/alibi_sdk/plugins/kafka_plugin.py`](https://github.com/valid22/alibi-ai/blob/main/python/alibi_sdk/alibi_sdk/plugins/kafka_plugin.py)

## `KafkaPlugin`

**Bases:** `Plugin`

#### `__init__`

```python theme={null}
def __init__(bootstrap_servers: Optional[str] = None, topic_prefix: str = 'alibi.', store: Optional[_InMemoryKafka] = None, client_factory: Optional[Callable[[], Any]] = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `bootstrap_servers` | `Optional[str]` |
| `topic_prefix` | `str` |
| `store` | `Optional[_InMemoryKafka]` |
| `client_factory` | `Optional[Callable[[], Any]]` |

**Returns**

`None`

#### `active_prefix`

```python theme={null}
def active_prefix() -> str
```

**Returns**

`str`

#### `connect`

```python theme={null}
async def connect() -> Any
```

Optional real client hook; in-memory store is always used for observe.

**Returns**

`Any`

#### `close`

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

**Returns**

`None`

#### `produce`

```python theme={null}
async def produce(topic: str, value: Any, key: Any = None, headers: Optional[dict[str, str]] = None) -> dict[str, Any]
```

**Parameters**

| Name | Type |
| - | - |
| `topic` | `str` |
| `value` | `Any` |
| `key` | `Any` |
| `headers` | `Optional[dict[str, str]]` |

**Returns**

`dict[str, Any]`

#### `consume`

```python theme={null}
async def consume(topic: str, from_offset: int = 0, max_messages: Optional[int] = None) -> list[dict[str, Any]]
```

**Parameters**

| Name | Type |
| - | - |
| `topic` | `str` |
| `from_offset` | `int` |
| `max_messages` | `Optional[int]` |

**Returns**

`list[dict[str, Any]]`

#### `snapshot`

```python theme={null}
async def snapshot(span: SpanContext) -> SnapshotHandle
```

**Parameters**

| Name | Type |
| - | - |
| `span` | `SpanContext` |

**Returns**

`SnapshotHandle`

#### `observe`

```python theme={null}
async def observe(span: SpanContext) -> dict[str, Any]
```

**Parameters**

| Name | Type |
| - | - |
| `span` | `SpanContext` |

**Returns**

`dict[str, Any]`

#### `restore`

```python theme={null}
async def restore(span: SpanContext, handle: SnapshotHandle) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `span` | `SpanContext` |
| `handle` | `SnapshotHandle` |

**Returns**

`None`

### `create_kafka_plugin`

```python theme={null}
def create_kafka_plugin(bootstrap_servers: Optional[str] = None, topic_prefix: str = 'alibi.', store: Optional[_InMemoryKafka] = None, client_factory: Optional[Callable[[], Any]] = None) -> KafkaPlugin
```

**Parameters**

| Name | Type |
| - | - |
| `bootstrap_servers` | `Optional[str]` |
| `topic_prefix` | `str` |
| `store` | `Optional[_InMemoryKafka]` |
| `client_factory` | `Optional[Callable[[], Any]]` |

**Returns**

`KafkaPlugin`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.