|
1 | 1 | # hotdata-marimo |
2 | 2 |
|
3 | | -Marimo widgets for [Hotdata](https://hotdata.dev): run SQL, browse catalogs, load managed databases, and display results in notebooks. |
4 | | - |
5 | | -Requires Python 3.10+, [Marimo](https://marimo.io/), and [hotdata-runtime](https://github.com/hotdata-dev/hotdata-runtime) (installed automatically). |
6 | | - |
7 | | -## Supported widgets |
8 | | - |
9 | | -Importing `hotdata_marimo` registers `mo.ui.hotdata_*` aliases for discoverability. |
10 | | - |
11 | | -| Widget | Function | Notes | |
12 | | -|--------|----------|-------| |
13 | | -| SQL editor | `hm.sql_editor(client)` | Returns `.ui` and `.result` | |
14 | | -| Table browser | `hm.table_browser(client)` | Browse connections, schemas, tables, columns | |
15 | | -| Managed databases panel | `hm.databases_panel(client)` | Create catalogs and load parquet files | |
16 | | -| Managed database writer | `hm.managed_database_writer(client)` | Lower-level create/load UI | |
17 | | -| Workspace selector | `hm.workspace_selector_from_env()` | Pick workspace when `HOTDATA_WORKSPACE` is unset | |
18 | | -| Connection picker | `hm.connection_picker(client)` | Dropdown of workspace connections | |
19 | | -| Connection status | `hm.connection_status(client)` | API / workspace health callout | |
20 | | -| Connections panel | `hm.connections_panel(client)` | Status callout plus connection list | |
21 | | -| Query result | `hm.query_result(result)` | Render a `QueryResult` as a table | |
22 | | -| Recent results | `hm.recent_results(client)` | Browse past query results | |
23 | | -| Run history | `hm.run_history(client)` | Recent query runs | |
24 | | - |
25 | | -Each widget also has a `mo.ui.hotdata_*` alias (e.g. `mo.ui.hotdata_sql_editor`). Native Marimo SQL cells are supported via `hm.register_hotdata_sql_engine()` and `mo.sql(..., engine=client)`. |
| 3 | +[Marimo](https://marimo.io/) widgets for [Hotdata](https://hotdata.dev) — run SQL, browse your schema, and work with managed databases in reactive notebooks. |
26 | 4 |
|
27 | 5 | ## Install |
28 | 6 |
|
29 | 7 | ```bash |
30 | 8 | pip install hotdata-marimo |
31 | 9 | ``` |
32 | 10 |
|
33 | | -Set `HOTDATA_API_KEY`. Optionally set `HOTDATA_WORKSPACE`, `HOTDATA_API_URL`, or `HOTDATA_SANDBOX`. |
34 | | - |
35 | | -## Connect |
36 | | - |
37 | | -```python |
38 | | -import hotdata_marimo as hm |
39 | | - |
40 | | -client = hm.from_env() |
41 | | -``` |
42 | | - |
43 | | -If `HOTDATA_WORKSPACE` is unset, pick a workspace interactively: |
44 | | - |
45 | | -```python |
46 | | -ws = hm.workspace_selector_from_env() |
47 | | -client = ws.client |
48 | | -``` |
| 11 | +## Authentication |
49 | 12 |
|
50 | | -## SQL editor widget |
| 13 | +Set `HOTDATA_API_KEY` in your environment. Optionally set `HOTDATA_WORKSPACE` to pin a specific workspace (the first available workspace is used if unset). |
51 | 14 |
|
52 | | -Run SQL in one cell; show results in the next. Marimo only renders what you **`return`**. |
| 15 | +## Quickstart |
53 | 16 |
|
54 | | -**Cell 1 — editor** |
| 17 | +Because Marimo reruns cells reactively, construct a widget in one cell and read its `.ui` or `.result` in the next. |
55 | 18 |
|
56 | 19 | ```python |
57 | | -import marimo as mo |
| 20 | +# Cell 1 |
58 | 21 | import hotdata_marimo as hm |
59 | 22 |
|
60 | 23 | client = hm.from_env() |
61 | 24 | editor = hm.sql_editor(client, default_sql="SELECT 1 AS ok") |
62 | 25 | return editor.ui |
63 | 26 | ``` |
64 | 27 |
|
65 | | -**Cell 2 — result** |
66 | | - |
67 | 28 | ```python |
| 29 | +# Cell 2 |
68 | 30 | return hm.query_result(editor.result) |
69 | 31 | ``` |
70 | 32 |
|
71 | | -Click **Run on Hotdata** after changing SQL. The editor caches the last successful result so downstream cells do not re-query on every refresh. |
| 33 | +Click **Run on Hotdata** after editing SQL. The editor caches the last successful result so downstream cells don't re-query on every refresh. |
72 | 34 |
|
73 | | -## Native Marimo SQL cells |
| 35 | +## Workspace selection |
| 36 | + |
| 37 | +If you have multiple workspaces or `HOTDATA_WORKSPACE` is unset, add an interactive picker. `ws.client` updates when the selection changes: |
| 38 | + |
| 39 | +```python |
| 40 | +ws = hm.workspace_selector_from_env() |
| 41 | +client = ws.client |
| 42 | +return ws.ui |
| 43 | +``` |
74 | 44 |
|
75 | | -Register the Hotdata engine once, then pass `engine=client` to `mo.sql`. Hotdata appears as **Hotdata** in the SQL connection picker. |
| 45 | +## Native Marimo SQL cells |
76 | 46 |
|
77 | | -**Setup cell** |
| 47 | +Register the Hotdata engine once and Hotdata will appear as a selectable engine in the SQL connection picker: |
78 | 48 |
|
79 | 49 | ```python |
| 50 | +# Setup cell |
80 | 51 | import marimo as mo |
81 | 52 | import hotdata_marimo as hm |
82 | 53 |
|
83 | 54 | hm.register_hotdata_sql_engine() |
84 | 55 | client = hm.from_env() |
85 | 56 | ``` |
86 | 57 |
|
87 | | -**SQL cell** |
88 | | - |
89 | 58 | ```python |
90 | | -_df = mo.sql( |
91 | | - """ |
92 | | - SELECT 1 AS example_value |
93 | | - """, |
94 | | - engine=client, |
95 | | -) |
| 59 | +# Any SQL cell |
| 60 | +_df = mo.sql("SELECT * FROM orders LIMIT 10", engine=client) |
96 | 61 | ``` |
97 | 62 |
|
98 | 63 |  |
99 | 64 |
|
100 | | -## Browse tables |
| 65 | +## Browse your schema |
| 66 | + |
| 67 | +The table browser lets you pick a connection, search for a table, and inspect its columns — with a starter query ready to copy: |
101 | 68 |
|
102 | 69 | ```python |
103 | 70 | browser = hm.table_browser(client) |
104 | 71 | return browser.ui |
105 | 72 | ``` |
106 | 73 |
|
107 | | -Pick a connection, schema, and table to inspect columns. Use `browser.selected_table` in downstream cells. |
| 74 | +Use `browser.selected_table` in downstream cells to reference the chosen table. |
108 | 75 |
|
109 | 76 | ## Managed databases |
110 | 77 |
|
111 | | -Create a Hotdata-owned catalog and load a parquet file from the notebook: |
| 78 | +View existing managed databases and load new parquet files from a single tabbed panel: |
112 | 79 |
|
113 | 80 | ```python |
114 | | -panel = hm.databases_panel(client) |
115 | | -return panel |
| 81 | +writer = hm.managed_database_writer(client) |
| 82 | +return writer.tab_ui |
116 | 83 | ``` |
117 | 84 |
|
118 | | -Or use the lower-level writer API: |
| 85 | +Or show just the read-only panel: |
119 | 86 |
|
120 | 87 | ```python |
121 | | -writer = hm.managed_database_writer(client) |
122 | | -return writer.ui |
| 88 | +return hm.databases_panel(client) |
123 | 89 | ``` |
124 | 90 |
|
125 | | -## Other helpers |
126 | | - |
127 | | -See [Supported widgets](#supported-widgets) for the full list. Quick examples: |
| 91 | +## All widgets |
| 92 | + |
| 93 | +| Widget | Code | What you get | |
| 94 | +|--------|------|-------------| |
| 95 | +| SQL editor | `hm.sql_editor(client)` | `.ui` to show the editor, `.result` to read rows | |
| 96 | +| Query result | `hm.query_result(result)` | Renders a `QueryResult` as a table | |
| 97 | +| Table browser | `hm.table_browser(client)` | Browse connections, tables, and column metadata | |
| 98 | +| Managed databases | `hm.databases_panel(client)` | Read-only list of managed databases | |
| 99 | +| Database writer | `hm.managed_database_writer(client)` | Create databases and load parquet files | |
| 100 | +| Workspace picker | `hm.workspace_selector_from_env()` | Dropdown to switch workspaces | |
| 101 | +| Connection picker | `hm.connection_picker(client)` | Dropdown of connections in the workspace | |
| 102 | +| Connection status | `hm.connection_status(client)` | Health callout for the API and workspace | |
| 103 | +| Connections panel | `hm.connections_panel(client)` | Status + list of connections | |
| 104 | +| Recent results | `hm.recent_results(client)` | Browse past query results | |
| 105 | +| Run history | `hm.run_history(client)` | Recent query runs | |
128 | 106 |
|
129 | | -```python |
130 | | -return hm.connection_status(client) |
131 | | -return hm.connections_panel(client) |
132 | | -return hm.recent_results(client).ui |
133 | | -return hm.run_history(client) |
134 | | -``` |
| 107 | +All widgets are also available as `mo.ui.hotdata_*` aliases (e.g. `mo.ui.hotdata_sql_editor`) for discovery via Marimo's autocomplete. |
135 | 108 |
|
136 | 109 | ## Demo notebook |
137 | 110 |
|
138 | 111 | ```bash |
139 | 112 | uv run marimo edit examples/demo.py --no-token |
140 | 113 | ``` |
141 | 114 |
|
142 | | -`examples/demo.py` combines workspace selection, catalog browsing, managed databases, query history, and a native `mo.sql` cell. |
| 115 | +The demo combines workspace selection, schema browsing, managed databases, query history, and a native SQL cell in a single tabbed interface. |
143 | 116 |
|
144 | 117 | ## Development |
145 | 118 |
|
146 | 119 | ```bash |
147 | 120 | uv sync --locked |
148 | 121 | uv run pytest |
149 | 122 | ``` |
150 | | - |
151 | | -See [hotdata-runtime](https://github.com/hotdata-dev/hotdata-runtime) for the underlying API client. |
0 commit comments