Skip to content

docs: add marimo as an sql client #3593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 changes: 2 additions & 0 deletions docs/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import Hashboardsvg from '@site/static/images/integrations/logos/hashboard.svg';
import luzmo_logo from '@site/static/images/integrations/logos/luzmo.png';
import vs_logo from '@site/static/images/integrations/logos/logo_vs.png';
import chartbrew_logo from '@site/static/images/integrations/logos/logo_chartbrew.png';
import marimo_logo from '@site/static/images/integrations/logos/logo_marimo.png';
import Image from '@theme/IdealImage';

ClickHouse integrations are organized by their support level:
Expand Down Expand Up @@ -384,4 +385,5 @@ We are actively compiling this list of ClickHouse integrations below, so it's no
|TricksterCache|<Trickstercachesvg className="image" alt="TricksterCache logo" style={{width: '3rem'}}/>|Data visualization| Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator |[Website](https://trickstercache.org/)|
|Visual Studio Client|<Image img={vs_logo} size="logo" alt="VS logo"/>|Language client|Visual studio lightweight client|[Marketplace](https://marketplace.visualstudio.com/items?itemName=fanruten.clickhouse-light)|
|VulcanSQL|<Image img={vulcansql_logo} size="logo" alt="VulcanSQL logo"/>|Data API Framework|It's a Data API Framework for data applications that helps data folks create and share data APIs faster. It turns your SQL templates into data APIs. No backend skills required.|[Website](https://vulcansql.com/), <br/>[Documentation](https://vulcansql.com/docs/connect/clickhouse)|
|marimo|<Image img={marimo_logo} size="logo" alt="marimo logo"/>|SQL Client|An open-source reactive notebook for Python with SQL built-in. Create data visualizations, shareable apps or executable scripts.|[Website](https://marimo.io/), <br/>[Documentation](https://docs.marimo.io/guides/working_with_data/sql/?h=sql#clickhouse-support)|
</div>
16 changes: 8 additions & 8 deletions docs/integrations/sql-clients/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
slug: /integrations/sql-clients/
description: 'Overview page for ClickHouse SQL clients.'
keywords: ['integrations', 'DataGrip', 'DBeaver', 'DbVisualizer', 'Jupyter Notebooks', 'QStudio', 'TABLUM.IO']
keywords: ['integrations', 'DataGrip', 'DBeaver', 'DbVisualizer', 'Jupyter Notebooks', 'QStudio', 'TABLUM.IO', 'marimo']
title: 'SQL Client Integrations'
---

Expand All @@ -11,10 +11,10 @@ This section describes how to integrate ClickHouse with various common database

| Tool | Description |
|-----------------------------------------------------|-------------------------------------------------------------|
| [DataGrip](/integrations/datagrip) | Powerful database IDE |
| [DBeaver](/integrations/dbeaver) | Database administration and development tool |
| [DbVisualizer](/integrations/dbvisualizer) | Database management tool for developers, DBAs, and analysts |
| [Jupyter Notebooks](/integrations/jupysql) | Interactive notebooks for code, visualizations, and text |
| [QStudio](/integrations/qstudio) | Free, open-source SQL GUI client |
| [TABLUM.IO](/integrations/tablumio) | Cloud-based data visualization platform |

| [DataGrip](/integrations/datagrip) | Powerful database IDE |
| [DBeaver](/integrations/dbeaver) | Database administration and development tool |
| [DbVisualizer](/integrations/dbvisualizer) | Database management tool for developers, DBAs, and analysts |
| [Jupyter Notebooks](/integrations/jupysql) | Interactive notebooks for code, visualizations, and text |
| [QStudio](/integrations/qstudio) | Free, open-source SQL GUI client |
| [TABLUM.IO](/integrations/tablumio) | Cloud-based data visualization platform |
| [marimo](/integrations/marimo) | Open-source reactive notebook for Python with SQL built-in |
121 changes: 121 additions & 0 deletions docs/integrations/sql-clients/marimo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
slug: /integrations/marimo
sidebar_label: 'marimo'
description: 'marimo is a next-generation Python notebook for interacting with data'
title: 'Using marimo with ClickHouse'
---

import Image from '@theme/IdealImage';
import marimo_connect from '@site/static/images/integrations/sql-clients/marimo/clickhouse-connect.gif';
import add_db_panel from '@site/static/images/integrations/sql-clients/marimo/panel-arrow.png';
import add_db_details from '@site/static/images/integrations/sql-clients/marimo/add-db-details.png';
import run_cell from '@site/static/images/integrations/sql-clients/marimo/run-cell.png';
import choose_sql_engine from '@site/static/images/integrations/sql-clients/marimo/choose-sql-engine.png';
import results from '@site/static/images/integrations/sql-clients/marimo/results.png';
import dropdown_cell_chart from '@site/static/images/integrations/sql-clients/marimo/dropdown-cell-chart.png';
import run_app_view from '@site/static/images/integrations/sql-clients/marimo/run-app-view.png';
import CommunityMaintainedBadge from '@theme/badges/CommunityMaintained';

# Using marimo with ClickHouse

<CommunityMaintainedBadge/>

[marimo](https://marimo.io/) is an open-source reactive notebook for Python with SQL built-in. When you run a cell or interact with a UI element, marimo automatically runs affected cells (or marks them as stale), keeping code and outputs consistent and preventing bugs before they happen. Every marimo notebook is stored as pure Python, executable as a script, and deployable as an app.

<Image img={marimo_connect} size="md" border alt="Connect to ClickHouse" />

## 1. Install marimo with SQL support {#install-marimo-sql}

```shell
pip install "marimo[sql]" clickhouse_connect
marimo edit clickhouse_demo.py
```
This should open up a web browser running on localhost.

## 2. Connecting to ClickHouse. {#connect-to-clickhouse}

Navigate to the datasources panel on the left side of the marimo editor and click on 'Add database'.

<Image img={add_db_panel} size="sm" border alt="Add a new database" />

You will be prompted to fill in the database details.

<Image img={add_db_details} size="md" border alt="Fill in the database details" />

You will then have a cell that can be run to establish a connection.

<Image img={run_cell} size="md" border alt="Run the cell to connect to ClickHouse" />

## 3. Run SQL {#run-sql}

Once you have set up a connection, you can create a new SQL cell and choose the clickhouse engine.

<Image img={choose_sql_engine} size="md" border alt="Choose SQL engine" />

For this guide, we will use the New York Taxi dataset.

```sql
CREATE TABLE trips (
trip_id UInt32,
pickup_datetime DateTime,
dropoff_datetime DateTime,
pickup_longitude Nullable(Float64),
pickup_latitude Nullable(Float64),
dropoff_longitude Nullable(Float64),
dropoff_latitude Nullable(Float64),
passenger_count UInt8,
trip_distance Float32,
fare_amount Float32,
extra Float32,
tip_amount Float32,
tolls_amount Float32,
total_amount Float32,
payment_type Enum('CSH' = 1, 'CRE' = 2, 'NOC' = 3, 'DIS' = 4, 'UNK' = 5),
pickup_ntaname LowCardinality(String),
dropoff_ntaname LowCardinality(String)
)
ENGINE = MergeTree
PRIMARY KEY (pickup_datetime, dropoff_datetime);
```

```sql
INSERT INTO trips
SELECT
trip_id,
pickup_datetime,
dropoff_datetime,
pickup_longitude,
pickup_latitude,
dropoff_longitude,
dropoff_latitude,
passenger_count,
trip_distance,
fare_amount,
extra,
tip_amount,
tolls_amount,
total_amount,
payment_type,
pickup_ntaname,
dropoff_ntaname
FROM gcs(
'https://storage.googleapis.com/clickhouse-public-datasets/nyc-taxi/trips_0.gz',
'TabSeparatedWithNames'
);
```

```sql
SELECT * FROM trips LIMIT 1000;
```

<Image img={results} size="lg" border alt="Results in a dataframe" />

Now, you are able to view the results in a dataframe. I would like to visualize the most expensive drop-offs from a given pickup location. marimo provides several UI components to help you. I will use a dropdown to select the location and altair for charting.

<Image img={dropdown_cell_chart} size="lg" border alt="Combination of dropdown, table and chart" />

marimo's reactive execution model extends into SQL queries, so changes to your SQL will automatically trigger downstream computations for dependent cells (or optionally mark cells as stale for expensive computations). Hence the chart and table changes when the query is updated.

You can also toggle App View to have a clean interface for exploring your data.

<Image img={run_app_view} size="md" border alt="Run app view" />
5 changes: 5 additions & 0 deletions scripts/aspell-ignore/en/aspell-dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ aiochclient
alloc
allocator
alphaTokens
altair
amplab
analysisOfVariance
analytics
Expand Down Expand Up @@ -1765,12 +1766,14 @@ dashboarding
datacenter
datacenters
datafiles
dataframe
datagrip
datalens
datanode
dataset
datasets
datasource
datasources
datatypes
dateName
dateTime
Expand Down Expand Up @@ -2372,6 +2375,8 @@ mappedfile
marginBottom
marginLeft
mariadb
marimo
marimo's
matcher
materializations
materializedview
Expand Down
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ const sidebars = {
"integrations/sql-clients/jupysql",
"integrations/sql-clients/qstudio",
"integrations/sql-clients/tablum",
"integrations/sql-clients/marimo",
],
},
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading