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

# Marimo

> How to integrate the database with Marimo, a reactive Python notebook for reproducible and interactive data analysis.

Integrate your cluster with [Marimo](https://marimo.io/), a reactive Python notebook built for reproducibility and interactivity.

## Prerequisites

First, start by installing Marimo and setting up a notebook according to the [Marimo quickstart documentation](https://github.com/marimo-team/marimo#quickstart).

You will also need the following packages:

```bash theme={null}
pip install starrocks sqlalchemy pandas
```

## Connecting to the database

Use [SQLAlchemy](https://www.sqlalchemy.org/) to create a connection engine. The connection string format is:

```
starrocks://username:password@host:port/database
```

```python theme={null}
import marimo as mo
import sqlalchemy as sa

engine = sa.create_engine("starrocks://username:password@<host>:9030")
```

Replace `<host>` with your database FE host.

## Using Marimo UI for credentials

To avoid hardcoding credentials, use Marimo's interactive UI elements to collect them at runtime.

**Cell 1** — render input fields:

```python theme={null}
user = mo.ui.text(label="Username")
pw = mo.ui.text(label="Password", kind="password")
mo.hstack([user, pw])
```

**Cell 2** — create the engine using the entered values:

```python theme={null}
engine = sa.create_engine(
    f"starrocks://{user.value}:{pw.value}@<host>:9030"
)
```

## Querying the database

With the engine established, use pandas to run queries:

```python theme={null}
import pandas as pd

df = pd.read_sql("SELECT * FROM my_database.my_table LIMIT 100", engine)
mo.ui.table(df)
```

![Marimo notebook connected to the database](https://mintcdn.com/mirrorship-docs/8gpPdHU-sBXASb5i/documents/images/21ac24e8691be17843809f3f.png?fit=max\&auto=format\&n=8gpPdHU-sBXASb5i\&q=85\&s=2c6023943edcd7d4bc919d322de17307)

**Note**

Multi-catalog support requires Marimo version 0.22.5 or later.


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