Skip to main content

Stof

JSON that runs.

Stof is JSON with functions. Put the logic next to the data, and your app runs the document in a sandbox that can only touch what you hand it. In Rust, JavaScript, and Python.

Try it in your browser · Docs · Discord

JSON, plus a function

// acme.stof: one customer's pricing
{
    "customer": "acme",
    "plan": { "rate": 0.02, "included": 1000 },

    fn price(units: int) -> float {
        const billable = units - self.plan.included;
        if (billable <= 0) return 0;
        billable * self.plan.rate
    }
}
import { StofDoc } from '@formata/stof';

const doc = await StofDoc.new(source);   // acme.stof
await doc.call('price', 5000);           // 80
from pystof import Doc

doc = Doc()
doc.parse(source)                         # acme.stof
doc.call('price', 5000)                   # 80.0

Any JSON is already a Stof document. Add a function where the logic belongs, and your app calls it the way it reads a field. The document runs inside your process: no server, no container, and it can't reach anything you didn't give it.

What else a document can hold

// server.stof
ms timeout: 5min + 30s        // 330000
MiB memory: 2GB               // about 1907.35

#[type]
Server: {
    #[schema((v: int): bool => v > 0 && v < 65536)]
    int port: 8080
}

config: { port: 70000 }

fn valid() -> bool { <Server>.schemafy(self.config) }

#[test]
fn config_is_valid() { assert(self.valid()); }
  • Units are part of the number, and math between them converts. No more "timeout": "5m" for someone to parse later.
  • Types carry rules for their fields. Point one at any object to check it: this config fails, because 70000 isn't a port.
  • Tests live next to what they check. stof test server.stof fails here until the port is fixed.

There's more: destructuring, async, attributes, and imports and exports for JSON, YAML, TOML, and compact binary.

It can only touch what you hand it

const doc = await StofDoc.new(`
    fn greet(name: str) -> str { Host::greet(name) }
    fn leak() -> str { fs::read('/etc/passwd') }
`);

doc.lib('Host', 'greet', (name) => `hello, ${name}`);

await doc.call('greet', 'world');   // 'hello, world'
await doc.call('leak');
// throws: 'fs::read' isn't available: this host hasn't given documents file system access

The same in Python:

doc.lib('Host', 'greet', lambda name: f'hello, {name}')

doc.call('greet', 'world')   # 'hello, world'
doc.call('leak')             # raises ValueError: 'fs::read' isn't available: ...

A document sees itself and the functions your app registers. There's no file system, network, or environment unless you turn them on, and network access can be limited to the hosts you list (doc.allowHttp(['api.example.com']) in JavaScript, doc.allow_http_hosts(['api.example.com']) in Python). Every call has a time and memory limit. You can also seal the parts you trust, so nothing can change them, and confine code from somewhere else so it sees only what you list. See Security and the Sandbox.

What it's for

  • Logic someone else writes. A model, a user, or a customer gives you rules, filters, transforms, scoring, or agent tools. Check them, test them, and run them in-process on every request.
  • Behavior per customer. One document per customer holds their rules, limits, and state. An agent can edit it, a person reviews a one-line diff, and your app behaves differently for that customer with no deploy.
  • Config that checks itself. Validate and compute values in the config, and still export plain JSON, YAML, or TOML.
  • The rules engine or DSL you were about to build. Describe your domain in Stof instead.
  • Logic that has to run everywhere. Send a document, functions included, as text or compact binary, and get the same answer in the browser, on a server, or in a worker.

Each one has a runnable example in the playground. Use something else for your own application code, heavy compute, or long-running services: write those in your main language and give them to documents as functions.

Stof is the engine behind Limitr, where every customer's pricing is a Stof document, evaluated in-process on every call.

Install

npm i @formata/stof     # JavaScript / TypeScript
cargo add stof          # Rust
pip install stof        # Python (import pystof)

The stof command line (stof run, stof test, and the language server) is prebuilt for macOS, Linux, and Windows. See stof-cli, or on macOS and Linux:

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/dev-formata-io/stof-cli/releases/latest/download/stof-cli-installer.sh | sh

TypeScript

import { stofAsync } from '@formata/stof';

const doc = await stofAsync`
    "name": "Stof"
    fn hello() -> str { \`Hello, \${self.name}!\` }
`;
console.log(await doc.call('hello')); // Hello, Stof!

Python

from pystof import Doc

doc = Doc()
doc.parse('rate: 2\nfn total(units: int) -> float { units * self.rate }')
print(doc.call('total', 21))  # 42.0

Rust

use stof::model::Graph;
use stof::runtime::{Runtime, Val};

let mut graph = Graph::default();
graph.parse_stof_src("rate: 2\nfn total(units: int) -> float { units * self.rate }", None, Default::default())?;
let total = Runtime::call(&mut graph, "total", vec![Val::from(21i64)])?; // 42

Teaching a model Stof: give it content/SKILL.md, a short guide to the language, with the library references in content/stof.zip. The npm package ships the same skill in node_modules/@formata/stof/skill/stof.

FAQ

Is it safe to run a document a model wrote? That's what it's built for. A document can only see itself and the functions your app gives it. File system, environment, file imports, and network are off by default in every language, and network access never reaches localhost or your private network unless you list those hosts. Each call has a time limit (2 minutes by default) and a memory limit (256 MB by default), so a runaway document fails its call instead of your app. For code from somewhere else, parse it as untrusted (nothing runs while it's parsed) and seal it confined to what you list. The stof CLI turns access on, since it runs your own files.

Can models write Stof? Yes. It reads like JSON and JavaScript, which every model already knows, and errors give the exact line and a plain explanation, so a model can fix its own mistakes. The skill helps.

Why not have the model write Python and run it in a container? You can, but that's infrastructure, startup time, and a lot of access to lock down, and what a person reviews is a program. Stof runs inside your process, starts instantly, has no access by default, and a change is a diff to a document.

Why not Lua? Lua is a great language for scripting your own app. Stof is for documents that carry logic. With Lua, the data lives somewhere else, each host language needs its own Lua binding, and schemas, units, tests, and the sandbox are yours to build. A Stof document holds the data and its logic together, runs the same in Rust, JavaScript, and Python, and starts with no access. Any JSON is already a Stof document, so there's nothing to migrate.

Why not CEL or JSONLogic? Expression languages are safe because they're small: one expression, no functions of your own, no state. That's enough for a single condition, and it runs out quickly for pricing, scoring, or an agent's tools. Stof has functions, types, and tests, inside the same kind of sandbox.

Why not WebAssembly? WebAssembly needs a compiler toolchain, and its binaries are large to send. Stof is readable, small, and travels with the data it works on. (The Stof runtime itself is compiled to WebAssembly for browsers.)

How fast is it? A small document parses and runs in under a millisecond, and calls after that take microseconds.

Can a document depend on other documents, or on remote data? Yes, with one pinned line that works the same in every host, the browser included. The host calls load() after parsing, and the document fetches what it depends on through the host's own network rules, checks it against its sha256, and parses it in: Stof, a package, JSON, CSV, an image, any file. Packages have versions (the highest one required wins), and the stof CLI pins, installs, and updates them:

#[load] fn intent() { await import('https://github.com/formata/intent/releases/download/v1.4.0/intent.pkg', '9f2c...', '@formata/intent@1.4.0'); }

Do I have to replace JSON, YAML, or TOML? No. Stof imports and exports them, so you can add logic to the data you already have.

Learn more

License

Apache 2.0. See LICENSE.

Metadata

Release files for stof 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stof 0.12.0
File Size Uploaded Provenance Actions
stof-0.12.0.tar.gz 767.4 kB With provenance Details for stof-0.12.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for stof 0.12.0
File Actions
stof-0.12.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for stof-0.12.0-cp38-abi3-win_amd64.whl
stof-0.12.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details for stof-0.12.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
stof-0.12.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details for stof-0.12.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
stof-0.12.0-cp38-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64 Details for stof-0.12.0-cp38-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl

Total release size: 44.3 MB

Release files / stof-0.12.0.tar.gz

Download URL stof-0.12.0.tar.gz
Size 767.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fd001612466b5abb86fbde50089697a903ad012682f9c92e0c4fea16a6f196fb
BLAKE2b-256 checksum
How to use checksums
384d385a596dae03b4f9fb801c9923b53741562f8c351c28102612718973c9a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / stof-0.12.0-cp38-abi3-win_amd64.whl

Download URL stof-0.12.0-cp38-abi3-win_amd64.whl
Size 8.7 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4f95b2bf821a8c931e5a9f3695c453fa0671cee2e011020fc10c9c942f973023
BLAKE2b-256 checksum
How to use checksums
cfa6e13648642a8a06be18b3e140f1529ab4ccbe7c5787c1c1ee55d14485cabe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / stof-0.12.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL stof-0.12.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.1 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4daacc406018a03f60b7c5663a7c2778948f1f6460eeb9c47eef826b9741bdd4
BLAKE2b-256 checksum
How to use checksums
ce061872e902e0abfb063977cc888a7dd837933db076189dc27bc9d2fcf315f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / stof-0.12.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL stof-0.12.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 8.8 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2f603671788fa429e63376d951f37b5eb20ed2029478e0c249d4e7005c66e0da
BLAKE2b-256 checksum
How to use checksums
d2f3212d745e74002a0057d1d32c1d70b6668c0deaeed0dccd4225760155d30d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / stof-0.12.0-cp38-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl

Download URL stof-0.12.0-cp38-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl
Size 16.9 MB
Tags CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1ea0b7f94cc9d0dbfca08556cdfedd829c3e5ccbbfa8d17718ef1cea0c5167a2
BLAKE2b-256 checksum
How to use checksums
569ee39e5508816a38776401b6e5c004120538baa7c16a238bc40e26c9541acf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for stof 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for stof-0.12.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page