Skip to content

Commit 5393488

Browse files
committed
docs: simplify README with usage examples and SQL screenshot
1 parent 89353fe commit 5393488

2 files changed

Lines changed: 64 additions & 49 deletions

File tree

README.md

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
# hotdata-marimo
22

3-
Marimo UI helpers for [Hotdata](https://hotdata.dev): run SQL from a notebook, browse catalog metadata, and render results as tables.
3+
Marimo widgets for [Hotdata](https://hotdata.dev): run SQL, browse catalogs, load managed databases, and display results in notebooks.
44

5-
## Features
6-
7-
- **Workspace-aware setup** — build a `HotdataClient` from environment variables, or use `workspace_selector_from_env()` to choose a workspace interactively when no workspace is pinned.
8-
- **Connection health** — show a compact status callout with API, workspace, and optional sandbox context.
9-
- **Catalog browsing** — browse Hotdata connections, schemas, tables, and columns from Marimo UI controls.
10-
- **SQL editor widget** — run SQL against Hotdata, cache the latest successful result, and render results in downstream reactive cells.
11-
- **Native `mo.sql` engine** — register `HotdataMarimoEngine` so Marimo SQL cells can execute through a live `HotdataClient` with `engine=client`.
12-
- **Result display helpers** — render query results, recent results, and run history as notebook-friendly UI.
13-
- **Managed databases** — create Hotdata-owned catalogs, declare tables, and load parquet files (replaces dataset uploads for writes).
14-
- **Marimo UI aliases** — importing `hotdata_marimo` attaches helpers such as `mo.ui.hotdata_sql_editor` and `mo.ui.hotdata_table_browser` for discoverability.
5+
Requires Python 3.10+, [Marimo](https://marimo.io/), and [hotdata-runtime](https://github.com/hotdata-dev/hotdata-runtime) (installed automatically).
156

167
## Install
178

189
```bash
19-
uv pip install hotdata-marimo
20-
# or: pip install hotdata-marimo
10+
pip install hotdata-marimo
2111
```
2212

23-
Requires Python 3.10+, **Marimo**, and [**hotdata-runtime**](https://github.com/hotdata-dev/hotdata-runtime) (Hotdata SDK + runtime/session semantics — pulled in automatically when you `pip install hotdata-marimo`).
13+
Set `HOTDATA_API_KEY`. Optionally set `HOTDATA_WORKSPACE`, `HOTDATA_API_URL`, or `HOTDATA_SANDBOX`.
2414

25-
## Environment
15+
## Connect
2616

27-
| Variable | Required | Description |
28-
|----------|----------|-------------|
29-
| `HOTDATA_API_KEY` | Yes | API key for the Hotdata API |
30-
| `HOTDATA_API_URL` | No | API base URL (default: `https://api.hotdata.dev`) |
31-
| `HOTDATA_WORKSPACE` | No | Workspace id; if unset, the first active workspace is used |
32-
| `HOTDATA_SANDBOX` | No | Sandbox session id, passed through to the SDK |
17+
```python
18+
import hotdata_marimo as hm
3319

34-
## Minimal notebook
20+
client = hm.from_env()
21+
```
22+
23+
If `HOTDATA_WORKSPACE` is unset, pick a workspace interactively:
24+
25+
```python
26+
ws = hm.workspace_selector_from_env()
27+
client = ws.client
28+
```
29+
30+
## SQL editor widget
31+
32+
Run SQL in one cell; show results in the next. Marimo only renders what you **`return`**.
33+
34+
**Cell 1 — editor**
3535

3636
```python
3737
import marimo as mo
@@ -42,25 +42,30 @@ editor = hm.sql_editor(client, default_sql="SELECT 1 AS ok")
4242
return editor.ui
4343
```
4444

45+
**Cell 2 — result**
46+
4547
```python
4648
return hm.query_result(editor.result)
4749
```
4850

49-
Importing `hotdata_marimo` registers discoverability aliases on Marimo’s UI namespace, so you can also use `mo.ui.hotdata_sql_editor`, `mo.ui.hotdata_table_browser`, `mo.ui.hotdata_query_result`, and `mo.ui.hotdata_connection_status`.
51+
Click **Run on Hotdata** after changing SQL. The editor caches the last successful result so downstream cells do not re-query on every refresh.
5052

51-
Use `hm.connection_status(client)` (or `mo.ui.hotdata_connection_status(client)`) for a small API/workspace health callout.
53+
## Native Marimo SQL cells
5254

53-
## Marimo SQL Cells
55+
Register the Hotdata engine once, then pass `engine=client` to `mo.sql`. Hotdata appears as **Hotdata** in the SQL connection picker.
5456

55-
Register the Hotdata SQL engine once during setup, then pass a `HotdataClient` to Marimo SQL cells:
57+
**Setup cell**
5658

5759
```python
60+
import marimo as mo
5861
import hotdata_marimo as hm
5962

6063
hm.register_hotdata_sql_engine()
6164
client = hm.from_env()
6265
```
6366

67+
**SQL cell**
68+
6469
```python
6570
_df = mo.sql(
6671
"""
@@ -70,46 +75,56 @@ _df = mo.sql(
7075
)
7176
```
7277

73-
The engine also exposes Hotdata catalog metadata to Marimo's data-source UI. Hotdata connections are labeled **Hotdata** in the SQL connection picker.
78+
![Marimo SQL cell with Hotdata selected in the database connections picker](docs/images/mo-sql-hotdata-connection.png)
79+
80+
## Browse tables
81+
82+
```python
83+
browser = hm.table_browser(client)
84+
return browser.ui
85+
```
86+
87+
Pick a connection, schema, and table to inspect columns. Use `browser.selected_table` in downstream cells.
7488

75-
## Two-cell pattern
89+
## Managed databases
7690

77-
Keep the editor in one cell and consume `editor.result` in another. The editor caches the last successful run so downstream cells do not re-query the API on every refresh; click **Run on Hotdata** again after you change SQL. While a query is running, a Marimo status spinner is shown.
91+
Create a Hotdata-owned catalog and load a parquet file from the notebook:
7892

79-
Marimo only shows **what you `return` from a cell**. Calling `mo.vstack(...)` or `hm.query_result(...)` without returning it produces no visible output.
93+
```python
94+
panel = hm.databases_panel(client)
95+
return panel
96+
```
8097

81-
See `examples/demo.py` for a full runnable notebook flow.
98+
Or use the lower-level writer API:
8299

83-
## Examples
100+
```python
101+
writer = hm.managed_database_writer(client)
102+
return writer.ui
103+
```
84104

85-
- `examples/demo.py` — tabbed explorer with workspace selection, connection health, managed databases (create + parquet load), recent results (selectable table), run history, and a native `mo.sql` cell.
105+
## Other helpers
86106

87-
Run locally (single-user machine):
107+
```python
108+
return hm.connection_status(client) # API / workspace callout
109+
return hm.recent_results(client).ui # past query results
110+
return hm.run_history(client) # recent query runs
111+
```
112+
113+
Importing `hotdata_marimo` also registers `mo.ui.hotdata_*` aliases (e.g. `mo.ui.hotdata_sql_editor`).
114+
115+
## Demo notebook
88116

89117
```bash
90118
uv run marimo edit examples/demo.py --no-token
91119
```
92120

93-
On a **shared or networked host**, omit `--no-token` and use the access token printed in the terminal URL. Without it, anyone who can reach the Marimo port can run queries against your Hotdata workspace.
94-
95-
## Layout
96-
97-
This repo is intentionally thin: **API client, env helpers, and result models** live in **hotdata-runtime**; **hotdata-marimo** only adds Marimo widgets (`sql_editor`, `table_browser`, `managed_database_writer`, `display` for tables/status/history, `workspace_selector`). Import `HotdataClient` / `QueryResult` / `from_env` from **`hotdata_marimo`** or directly from **`hotdata_runtime`**.
121+
`examples/demo.py` combines workspace selection, catalog browsing, managed databases, query history, and a native `mo.sql` cell.
98122

99123
## Development
100124

101-
This package depends on [**hotdata-runtime**](https://github.com/hotdata-dev/hotdata-runtime) (PyPI name `hotdata-runtime`). Development uses **uv**; keep a sibling checkout at `../hotdata-runtime` so the lockfile resolves the runtime from disk (see `[tool.uv.sources]` in `pyproject.toml`).
102-
103125
```bash
104126
uv sync --locked
105127
uv run pytest
106-
marimo edit examples/demo.py --no-token
107128
```
108129

109-
To pin **hotdata-runtime** from Git instead of the sibling path, remove the `[tool.uv.sources]` block, set the dependency line as needed, and run `uv lock` again.
110-
111-
For a **publishable** `uv.lock` (CI that only clones this repo), remove `[tool.uv.sources]`, point `hotdata-runtime` at PyPI or `git+https://…`, then `uv lock`.
112-
113-
The **`[project] name`** in [hotdata-runtime](https://github.com/hotdata-dev/hotdata-runtime) `pyproject.toml` is **`hotdata-runtime`** and the import package is **`hotdata_runtime`**.
114-
115-
Use **`--no-token`** for local development so the editor does not redirect to `/auth/login` (session auth is easy to hit with a global Marimo config). For a public or shared machine, omit it and use the printed URL with an access token instead.
130+
See [hotdata-runtime](https://github.com/hotdata-dev/hotdata-runtime) for the underlying API client.
48 KB
Loading

0 commit comments

Comments
 (0)