Skip to content

Installation

Install the single pystd package, then import the standard-library subpaths you need:

bash
pnpm add pystd
ts
import { hashlib, itertools, math, random } from "pystd";

math.factorial(10n);
hashlib.sha256(new TextEncoder().encode("hello"));
itertools.combinations(new BigInt64Array([1n, 2n, 3n]), 2);
random.seed(42n);
random.random();

Direct module subpaths are also available:

ts
import { factorial, sqrt } from "pystd/math";
import { sha256 } from "pystd/hashlib";
import { combinations } from "pystd/itertools";
import { random, seed } from "pystd/random";
import { mean } from "pystd/statistics";
import { dumps, loads } from "pystd/json";
import { uuid5, NAMESPACE_DNS } from "pystd/uuid";

Other portable subpaths are fractions, decimal, hmac, base64, binascii, bisect, heapq, string, textwrap, csv, html, urllib-parse, datetime, and calendar.

The generated packages are ESM-only and require Node.js 22.12 or newer. Browser and edge runtimes must support the WebAssembly features emitted by jco.

All subpaths share one internal CPython WebAssembly runtime and initialization promise. There are no separate scoped packages to install or deduplicate.

random uses CPython's deterministic pseudorandom algorithm and matches CPython for explicit seeds. Its omitted-seed convenience API uses the current time because the portable runtime has no OS entropy source. Do not use it for tokens, keys, or other security-sensitive values.

See Browser and Node.js setup for runtime requirements, bundler configuration, and end-to-end smoke-test commands.

Example

ts
const bytes = new TextEncoder().encode("hello");
const digest = sha256(bytes).hexdigest(undefined);

console.log(factorial(10n));
console.log(sqrt(2));
console.log(digest);