@kymoscope/sdk
v0.25.0
Published
The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.
Maintainers
Readme
@kymoscope/sdk
The Kymoscope data engine and its charts, without the app UI. The Kymoscope app (app.kymoscope.com) is the finished product; this package is the engine underneath it, so you can build your own interface around the same capabilities:
- import files and whole folders, including files too large for memory (DuckDB-WASM, out of core): delimited text (CSV, TSV,
.dat,.txt) and binary measurement files, MF4/MDF 3 (CAN decoded with a.dbcdropped alongside), EDF/BDF(+), XDF, TDMS, HDF5, MAT v5/v7.3 and COMTRADE; multi-rate files are combined on the fastest rate (datasets.splitByRategives one dataset per group), with cancel, progress and a channel chooser for very wide files - laps, overlays, dataset colours and time offsets
- worksheets of charts with a shared X axis and linked zoom
- 27 chart kinds, mounted as bare plots into your own elements
- math channels (formula columns) with an optional store adapter
- local and end-to-end encrypted live streams
- workspace / worksheet / chart import and export as JSON
- plan limits enforced by the engine and reported as events
Nothing you load goes through Kymoscope servers, except live streams relayed as ciphertext if you use them. The Kymoscope app is built on this package through the same public API (src/PlatformApp.tsx and src/workspace/Workspace.tsx are the reference host).
Install
npm install @kymoscope/sdk react react-domOr a script tag, pinned to a version: https://cdn.jsdelivr.net/npm/@kymoscope/[email protected]/dist/kymoscope-embed.js and …/dist/styles/charts.css (workers and DuckDB-WASM load from the same CDN folder). To self-host, copy node_modules/@kymoscope/sdk/dist into your static files (see Script tag below).
In this repo, build with npm -w @kymoscope/sdk run build.
| Output | Use |
|---|---|
| dist/kymoscope-sdk.js | ESM entry @kymoscope/sdk (react/react-dom 19 are peers: charts render with React) |
| dist/react.js | ESM entry @kymoscope/sdk/react (provider, hooks, <Chart>) |
| dist/kymoscope-embed.js | Standalone <script>: React bundled, global Kymoscope.createEngine |
| dist/assets/* | Web workers; keep them next to the JS file |
| dist/types/ | TypeScript declarations |
| dist/styles/charts.css | Chart styles and colour variables; load it once |
| dist/styles/tokens.css | Optional: Kymoscope's own theme tokens and its typeface (Plus Jakarta Sans, @font-face on the woff2 files in dist/styles/fonts/, SIL OFL 1.1 in fonts/OFL.txt); keep fonts/ next to it |
In the repo the package exports point at src/, so the app, site and admin build from source. npm pack and npm publish swap them for the dist/ entries (scripts/pack-manifest.mjs, restored afterwards); publishing runs only in GitHub Actions (.github/workflows/publish-sdk.yml).
Script tag
<link rel="stylesheet" href="/vendor/kymoscope/styles/charts.css" />
<div id="chart" style="height: 360px"></div>
<script src="/vendor/kymoscope/kymoscope-embed.js"></script>
<script>
const engine = Kymoscope.createEngine({ licenseKey: '…' })
engine.datasets.addColumns({ name: 'Run 42', columns: { t, speed, rpm }, units: { speed: 'km/h' } })
const chartId = engine.charts.add('multiband', { title: 'Speed & RPM' })
engine.charts.addSeries(chartId, 'speed')
engine.charts.addSeries(chartId, 'rpm')
const view = engine.charts.mount(chartId, document.getElementById('chart'))
</script>See examples/embed.html (run npx http-server packages and open /sdk/examples/embed.html).
React
import { createEngine } from '@kymoscope/sdk'
import { Chart, KymoscopeProvider, useEngine, useEngineState } from '@kymoscope/sdk/react'
import '@kymoscope/sdk/styles/charts.css'
// Create in an effect (and dispose in its cleanup) when the engine belongs to a component.
const engine = createEngine({ licenseKey: LICENSE_KEY })
function Charts() {
const charts = useEngineState((s) => s.worksheets.find((w) => w.id === s.activeWorksheetId)!.charts)
return charts.map((c) => (
<Chart key={c.id} id={c.id} style={{ height: 300 }} onStatus={…} onContextMenu={…} viewRef={…} />
))
}
<KymoscopeProvider engine={engine}><Charts /></KymoscopeProvider>The engine
createEngine(options) returns:
| Member | Purpose |
|---|---|
| getState(), subscribe(fn), on(event, fn) | Immutable EngineState; events change, limit, error, import |
| datasets | importFiles, warmImport, splitByRate, combine, chooseChannels, addColumns, addText, configure (parse config, laps), select/toggle, setColor, setOffset, remove, raw, columnBounds |
| folders | pick, canPick, fromFileList, fromDataTransfer, tree, isImportable |
| worksheets | add, rename, remove, reorder, activate, setXKey |
| charts | add, update, replaceSettings, rename, setBackground, remove, series ops (addSeries, updateSeries, …), layout metadata, mount, setFonts, kinds |
| view | setXRange, resetZoom, setLiveWindow |
| mathChannels | create, update, remove, importMany, importFile, exportBlob, preview, sync |
| live | openLocal, connect(descriptor, password), disconnect, rowCount |
| io | exportWorkspace/Worksheet/Chart, importWorkspace/Worksheet/Chart, parseFile, snapshot/restore, reset |
| data | merged(): the plotted data as one table |
| setOptions, licensed, isLicensed, dispose | Runtime options (limits, relay, store), license state, teardown |
Options (all optional): licenseKey, limits, mathChannels (a MathChannelStoreAdapter), live.relay ({ url, getToken(streamId) }), beforeImport.
Charts have no toolbar, menu or placeholder copy. A ChartView (from engine.charts.mount or <Chart viewRef>) reports status ('no-data' | 'empty' | 'ready'), contextmenu and viewchange, and offers exportPng(), setShiftMode(), autoscale(), setOptions() and destroy(). Style charts with --chart-bg, --chart-muted, --chart-grid, --accent and data-color-scheme="light" | "dark".
Failures throw KymoscopeError with a code (limit_reached carries detail.reason).
Encrypted live streams for your users
- Publish with the Python
kymoscopepackage (pip install kymoscope, Python 3.9+), the native LMU plugin, or the raw protocol, using your Kymoscope API key and a stream password. - Your backend asks for a watch ticket. The API key must never reach the browser:
POST {SUPABASE_URL}/functions/v1/stream-watch-ticket x-api-key: kymoscope_… {"streamId": "<uuid>"} → {"ticket": "wt.…", "expiresIn": 120, "stream": { "id", "name", "salt", "key_check" }} - The browser connects with that ticket and the stream password:
const engine = Kymoscope.createEngine({ live: { relay: { url: RELAY_URL, getToken: async (id) => (await myTicket(id)).ticket } } }) await engine.live.connect((await myTicket(streamId)).stream, password)
A ticket admits watching one stream for 2 minutes (the SDK renews it on open sockets) and nothing else. The relay only forwards ciphertext; frames are decrypted in the viewer's browser (PBKDF2-600k, AES-256-GCM).
Operator setup: set the same random WATCH_TICKET_SECRET on the relay Worker (wrangler secret put WATCH_TICKET_SECRET) and as a Supabase edge secret, and deploy stream-watch-ticket with verify_jwt = false.
Licensing
A license key is an offline-verified Ed25519 signature over { sub, domains, exp }. Domains can use wildcards (*.acme.com).
- Without a valid key everything works, and every mounted chart shows a small "Powered by Kymoscope" badge.
engine.licensedresolves to the result. - Every host needs a key that lists it,
localhostincluded. - Terms:
LICENSE.md(proprietary). Removing the attribution or tampering with the check is not permitted.
node scripts/license.mjs keygen --out ~/.kymoscope/kymoscope-license-private.jwk # once; keep it secret
node scripts/license.mjs sign --key ~/.kymoscope/kymoscope-license-private.jwk \
--sub acme --domains app.acme.com,*.acme.io --days 365The public key is compiled in (KYMOSCOPE_LICENSE_PUBLIC_KEY, src/embed/license.ts). Rotating it invalidates all issued keys.
Browser/CSP notes
- Workers: needs
worker-src 'self'(or the SDK's origin). - DuckDB-WASM: files too large for memory (over 100 million values or 300 MB) load DuckDB from
assets/(bundled, never a CDN), so allowblob:workers,connect-src 'self' blob:andscript-src 'wasm-unsafe-eval'. - Fonts: the SDK's JavaScript loads none. Pass your page's families to
engine.charts.setFonts({ sans, mono }). The optionaltokens.cssdeclares Plus Jakarta Sans from the woff2 files beside it (dist/styles/fonts/), so it is served from your origin (font-src 'self') and never from a font CDN.
