@screamer-labs/screamer
v2.5.0
Published
WASM build of screamer, a high-performance causal streaming time-series operator library, compiled from the same C++ core as the Python package.
Downloads
1,122
Maintainers
Readme
@screamer-labs/screamer
WASM build of screamer, a high-performance
causal streaming time-series operator library. It runs the same C++ core as the Python
screamer package, compiled to WebAssembly, in Node.js and the browser.
Install
npm i @screamer-labs/screamerThe package ships a single self-contained WASM module; there is no separate .wasm
asset to fetch and no build step on the consumer side.
The WASM module loads asynchronously
Call await ready() once, before constructing any op. Every factory reads the loaded
module, so using one beforehand throws.
import { ready, RollingMean } from "@screamer-labs/screamer";
await ready();
const op = RollingMean(3);Node, bundlers, and the browser
The import above works in Node (18+) and through any bundler (Vite, Next.js, webpack, esbuild), which inlines the embedded-WASM module. In a plain browser with no build step, import from a CDN URL instead (browser use needs 2.2.1 or newer):
<script type="module">
import { ready, RollingMean }
from "https://cdn.jsdelivr.net/npm/@screamer-labs/[email protected]/dist/index.js";
await ready();
const sma = RollingMean(3);
</script>Calling an op: four input regimes
An op factory like RollingMean(3) returns a callable. That callable dispatches on its
argument's type and preserves the container shape of its input: a scalar in gives a
scalar out, a typed array in gives a typed array out, and so on.
import { ready, RollingMean } from "@screamer-labs/screamer";
await ready();
// number -> number, one event at a time (the streaming regime).
const live = RollingMean(3);
live(1); // NaN, window not yet full
live(2); // NaN
live(3); // 2
// Float64Array -> Float64Array, container-preserving.
const fa = RollingMean(3)(new Float64Array([1, 2, 3, 4, 5]));
// Float64Array [ NaN, NaN, 2, 3, 4 ]
// number[] -> number[], container-preserving.
const arr = RollingMean(3)([1, 2, 3, 4, 5]);
// [ NaN, NaN, 2, 3, 4 ]
// async iterable -> async iterable, yielding one output per input event.
async function* events() {
for (const v of [1, 2, 3, 4, 5]) yield v;
}
const out = [];
for await (const y of RollingMean(3)(events())) out.push(y);
// [ NaN, NaN, 2, 3, 4 ]Each op instance is stateful and owns WASM-side memory. Call .dispose() when done
with it (live.dispose() above), rather than waiting on garbage collection.
Composing a pipeline
Input declares a named placeholder; passing it through op factories builds a
symbolic graph without running anything. Pipeline compiles that graph once and
returns a reusable function you call on stored data.
import { ready, Input, Pipeline, RollingMean, Diff } from "@screamer-labs/screamer";
await ready();
const x = Input("x");
const y = Diff(1)(RollingMean(3)(x));
const pipeline = new Pipeline([x], [y]);
const { values, index } = pipeline([1, 2, 3, 4, 5, 6]);
pipeline.dispose();pipeline(feeds) binds the declared inputs to data and runs the compiled graph in one
pass, so a multi-op chain does not recompute shared subgraphs. pipeline.live()
returns an event-by-event driver for streaming input; see the type definitions for its
push/advance/flush/result methods.
Parity with Python
This package is the JS/WASM build of the Python screamer
package: same operators, same causal semantics, same numerics. Its outputs are
verified against the Python package's outputs, and batch and streaming calls on the
same data give identical results.
Live demo
Watch the live trade dashboard in the browser:
screamer-labs.github.io/screamer/live-trades.html.
It shows low-lag price, volume-weighted fair value, order-flow pressure, and an optional VPIN view. The self-contained source is examples/live-trades.html.
Learn more
The live dashboard includes a local/UTC time selector and replays a bounded recent-trade buffer when its view or signal changes.
The JavaScript reference and guide are at screamer-labs.github.io/screamer. Full documentation, the function reference, and example notebooks are at screamer.readthedocs.io. Source and issues live at github.com/screamer-labs/screamer.
