> ## 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.sql

> Postgres plugin — generated from python/alibi_sdk source.

PostgreSQL plugin — sandbox schema isolation + query observation.

Apps use `plugin.execute` / `plugin.fetch` (or the returned pool wrappers)
so mutations and in-span reads land in the observation buffer.

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

## `PostgresPlugin`

**Bases:** `Plugin`

#### `__init__`

```python theme={null}
def __init__(connection_string: Optional[str] = None, schema: str = 'alibi_sandbox', tables: Optional[Sequence[str]] = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `connection_string` | `Optional[str]` |
| `schema` | `str` |
| `tables` | `Optional[Sequence[str]]` |

**Returns**

`None`

#### `active_schema`

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

**Returns**

`str`

#### `active_connection_string`

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

**Returns**

`str`

#### `connect`

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

**Returns**

`Any`

#### `close`

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

**Returns**

`None`

#### `ensure_schema`

```python theme={null}
async def ensure_schema(pool: Any = None, schema: Optional[str] = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `pool` | `Any` |
| `schema` | `Optional[str]` |

**Returns**

`None`

#### `execute`

```python theme={null}
async def execute(sql: str, *args: Any) -> str
```

Run a statement and record mutation observation when in a span.

**Parameters**

| Name | Type |
| - | - |
| `sql` | `str` |

**Returns**

`str`

#### `fetch`

```python theme={null}
async def fetch(sql: str, *args: Any) -> list[dict[str, Any]]
```

**Parameters**

| Name | Type |
| - | - |
| `sql` | `str` |

**Returns**

`list[dict[str, Any]]`

#### `fetchrow`

```python theme={null}
async def fetchrow(sql: str, *args: Any) -> Optional[dict[str, Any]]
```

**Parameters**

| Name | Type |
| - | - |
| `sql` | `str` |

**Returns**

`Optional[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_postgres_plugin`

```python theme={null}
def create_postgres_plugin(connection_string: Optional[str] = None, schema: str = 'alibi_sandbox', tables: Optional[Sequence[str]] = None) -> PostgresPlugin
```

**Parameters**

| Name | Type |
| - | - |
| `connection_string` | `Optional[str]` |
| `schema` | `str` |
| `tables` | `Optional[Sequence[str]]` |

**Returns**

`PostgresPlugin`


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