perspective-js 5.6.1

JavaScript/WebAssembly client for Perspective, a streaming query engine for data grids, pivot tables and charts.
Documentation

@perspective-dev/client

npm

Perspective is an open-source data grid, pivot table and charting component for large, real-time and streaming datasets.

@perspective-dev/client is the JavaScript and TypeScript API for Perspective's streaming query engine. The same Client connects to an engine running in a Web Worker (WebAssembly), in-process in Node.js, or remotely over WebSocket to a Python, Node.js or Rust server. It provides:

  • Table, a columnar, optionally indexed store which accepts Apache Arrow, CSV and JSON, and streams update() and remove() calls in real time. With page_to_disk, a Table pages its columns to disk (OPFS in the browser) to exceed memory.
  • View, an incrementally-maintained query over a Table: group_by, split_by pivots, aggregates, filters, sorts and columnar expressions.
  • Reactive joins across tables.
  • Virtual servers for DuckDB and ClickHouse, which translate View configurations into native SQL.

Installation

npm install @perspective-dev/client @perspective-dev/server

Usage

import perspective from "@perspective-dev/client";
import SERVER_WASM from "@perspective-dev/server/dist/wasm/perspective-server.wasm";

await perspective.init_server(fetch(SERVER_WASM));

const worker = await perspective.worker();
const table = await worker.table({ region: "string", sales: "float" });
const view = await table.view({
    group_by: ["region"],
    columns: ["sales"],
    aggregates: { sales: "sum" },
});

view.on_update(async () => console.log(await view.to_json()));
await table.update([{ region: "West", sales: 12.5 }]);

In Node.js the engine runs in-process, and the module exports the API directly:

const perspective = require("@perspective-dev/client");
const table = await perspective.table(data);

To render a Table as a data grid, pivot table or chart, see @perspective-dev/viewer.

Documentation