Starter templates

Copy and adapt working DuckDB SQL, Polars, and Python templates. Use public /v1/sample URLs immediately or plug in your bt_live_... key for full history.

DuckDB AS OF backtest query

backtest_asof.sql
Customize in Query Builder

Reconstruct the exact non-deleted state of ISO interconnection projects known on a past cutoff timestamp.

backtest_asof.sql
-- Point-in-time query in DuckDB
INSTALL httpfs; LOAD httpfs;
-- Optional for full file: CREATE OR REPLACE SECRET bt_auth (TYPE HTTP, BEARER_TOKEN 'bt_live_your_token');

WITH ranked AS (
  SELECT
    iso_region,
    queue_id,
    queue_status,
    capacity_mw,
    event_period_end_utc,
    known_time_utc,
    revision_seq,
    record_op,
    ROW_NUMBER() OVER (
      PARTITION BY iso_region, queue_id
      ORDER BY revision_seq DESC
    ) AS rn
  FROM 'https://bitemporal.dev/v1/sample/iso_interconnection_pit_v1.parquet'
  WHERE known_time_utc <= TIMESTAMP '2026-11-30 23:59:59+00'
)
SELECT iso_region, queue_id, queue_status, capacity_mw, event_period_end_utc, known_time_utc
FROM ranked
WHERE rn = 1 AND record_op NOT IN ('DELETE', 'RETRACT')
ORDER BY capacity_mw DESC NULLS LAST
LIMIT 25;

Polars revision diff across amendments

revision_diff.py
Customize in Query Builder

Compare initial vs latest known values for GPU cloud offers or clinical trials without writing a custom downloader.

revision_diff.py
import os
import polars as pl

TOKEN = os.environ["BITEMPORAL_API_KEY"]
URL = "https://bitemporal.dev/v1/datasets/gpu_cloud_pricing_pit_v1.parquet"

lf = pl.scan_parquet(URL, storage_options={"Authorization": f"Bearer {TOKEN}"})

revisions = (
    lf.filter(pl.col("record_op").is_in(["AMEND", "DELETE"]))
    .select([
        "provider",
        "instance_sku",
        "region",
        "revision_seq",
        "record_op",
        "price_usd_per_gpu_hour",
        "known_time_utc",
    ])
    .sort("known_time_utc", descending=True)
    .limit(50)
    .collect()
)
print(revisions)

Local incremental Parquet mirror script

sync_catalog.py
Customize in Query Builder

Check /v1/catalog SHA-256 hashes and download only files whose digest changed since your last sync.

sync_catalog.py
import hashlib
import os
from pathlib import Path
import httpx

BASE = "https://bitemporal.dev"
TOKEN = os.environ["BITEMPORAL_API_KEY"]
OUT_DIR = Path("./bitemporal_data")
OUT_DIR.mkdir(exist_ok=True)

with httpx.Client(timeout=60.0) as client:
    manifest = client.get(f"{BASE}/v1/catalog").json()
    for ds in manifest["datasets"]:
        target = OUT_DIR / f"{ds['dataset_id']}.parquet"
        if target.exists() and hashlib.sha256(target.read_bytes()).hexdigest() == ds["sha256"]:
            continue
        resp = client.get(ds["download_url"], headers={"Authorization": f"Bearer {TOKEN}"})
        if resp.status_code == 200:
            target.write_bytes(resp.content)
            print("updated", ds["dataset_id"], ds["row_count"])

Starter config & quota check

.env.example
Customize in Query Builder

Keep your key out of source control and verify your remaining daily request and bandwidth quota before running batch jobs.

.env.example
# Copy to .env (never commit live keys)
BITEMPORAL_API_KEY=bt_live_replace_me
BITEMPORAL_BASE_URL=https://bitemporal.dev

# Check remaining daily quota before running pipelines
curl -sS -H "Authorization: Bearer $BITEMPORAL_API_KEY" "$BITEMPORAL_BASE_URL/v1/account/status"