Metadata-Version: 2.5
Name: creeklytics
Version: 0.1.0
Summary: Publish tables from Databricks, Spark, pandas or Arrow into Creeklytics workbooks.
Project-URL: Homepage, https://app.creeklytics.com
Author: CreekData Technologies
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: creeklytics,data pipeline,databricks,parquet,reverse etl,spark,spreadsheet
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Database
Requires-Python: >=3.9
Requires-Dist: pyarrow>=12
Requires-Dist: requests>=2.28
Provides-Extra: pandas
Requires-Dist: pandas>=1.5; extra == 'pandas'
Provides-Extra: test
Requires-Dist: pandas>=1.5; extra == 'test'
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# creeklytics

Publish tables from **Databricks, Spark, pandas or Arrow** straight into a [Creeklytics](https://app.creeklytics.com) workbook. Your pipeline becomes the delivery layer: business users get a live, governed spreadsheet with lineage, version history, KPI alerts and an AI analyst that answers over every row.

```python
%pip install creeklytics

import creeklytics

df = spark.table("main.finance.revenue_summary")
creeklytics.publish(
    df,
    workbook_id="2024344f-....",                       # from the workbook URL
    sheet="revenue",
    token=creeklytics.databricks_secret("creeklytics", "publish_token"),
    source="main.finance.revenue_summary",
)
```

```
Published 41,203 rows to 'revenue' via json (version 6a1f…) [prepare 0.4s, publish 1.1s]
```

## How it works

| Table size | Route | Result in Creeklytics |
|---|---|---|
| ≤ 50,000 rows and < 8 MB | JSON | Regular sheet (supports `mode="append"`) |
| Up to 10,000,000 rows / 2 GB | Parquet: signed upload straight to storage, then commit | Big sheet (all rows, opens in seconds) |

`publish()` picks the route automatically. Every publish:

* swaps the sheet atomically — users never see half-loaded data, and nothing changes if any check fails;
* is verified at commit (storage checksum, row count and schema);
* saves a new version with lineage (source, notebook, job and run ids);
* keeps formulas, charts and pivots on other tabs working, and runs KPI alerts.

The published sheet is read-only in Creeklytics ("managed by a pipeline"); build analysis on other tabs.

## Setup

1. In Creeklytics, open the workbook → **⋯ → Publish from a pipeline… → Create token**. The token can only publish to that workbook.
2. Store it as a Databricks secret (never in notebook code):

   ```bash
   databricks secrets create-scope creeklytics
   databricks secrets put-secret creeklytics publish_token
   ```
3. Install in the notebook or job: `%pip install creeklytics` (or add it as a job library).

Outside Databricks, set `CREEKLYTICS_TOKEN` in the environment (and optionally `CREEKLYTICS_BASE_URL`).

## Usage

```python
import creeklytics

# Automatic route (recommended)
creeklytics.publish(df, workbook_id, sheet="orders", token=tok)

# Force a route
creeklytics.publish_json(small_df, workbook_id, "kpis", mode="append", token=tok)
creeklytics.publish_parquet(big_df, workbook_id, "orders", token=tok)

# Very large Spark tables: let Spark write the file to a Unity Catalog Volume
# instead of collecting to the driver (used automatically from 2M rows when a volume is given)
creeklytics.publish_parquet(big_df, workbook_id, "orders", token=tok,
                            volume="/Volumes/main/default/creeklytics_tmp")

# An existing Parquet file
creeklytics.publish("exports/orders.parquet", workbook_id, "orders", token=tok)
```

### Lineage

On Databricks the notebook path, job id and run id are captured automatically when available. For scheduled jobs, also pass task parameters `job_id = {{job.id}}` and `run_id = {{job.run_id}}`. Add the source table with `source="catalog.schema.table"`, or pass `lineage={...}` with `source`, `notebook`, `job_id`, `run_id`.

### Command line

```bash
export CREEKLYTICS_TOKEN=ckp_...
creeklytics publish orders.parquet --workbook <id> --sheet orders --source warehouse.orders
```

## Limits

* JSON route: 50,000 rows and 8 MB per publish; append keeps up to 200,000 rows in total.
* Parquet route: 10,000,000 rows and 2 GB per file. Files over 200 MB open best on 16 GB+ machines.
* 30 publishes per hour per token.
* A sheet is either JSON-published (regular) or Parquet-published (Big sheet); `publish()` switches to Parquet automatically if the target is already a Big sheet.
* Nested columns (arrays, structs, maps) aren't supported — flatten or cast to string first.

## Errors

`creeklytics.PublishError` has `.status` (HTTP status, 0 for client-side checks) and `.message`.

| Status | Meaning |
|---|---|
| 401 | Token missing, wrong or revoked |
| 403 | Token belongs to another workbook, or the workbook was deleted |
| 409 | Sheet name used by a sheet that isn't pipeline-managed (pick another name) |
| 413 | Too large for the route |
| 422 | Checksum, row count or schema mismatch — nothing changed; publish again |
| 429 | Rate limit — retry later |
| 500 | Server couldn't verify the file; the client retries the commit automatically |

## Good practice

* Validate before publishing (row counts, nulls in keys, schema). If validation fails, don't publish — the previous version stays live.
* Publish once per run to the real sheet. Don't publish samples or probes to a sheet users read.
* Publish results (marts, KPI tables) when you can; use the Parquet route when people need the full detail.

## License

Apache-2.0
