Skip to main content

Diaspore

Write Python. Ship JSON. Run it anywhere, sandboxed.

Diaspore compiles a large subset of Python into a portable JSON bundle and runs it with identical output on four runtimes: Python, Go, TypeScript and Lua. A bundle has no ambient authority, runs on a fuel budget, and can pause itself into a JSON snapshot that any other runtime can resume.

Playground | Specification | Security model | Examples | Releases

diaspore build app.py -o app.dsp.json     # compile once
diaspore run app.dsp.json                 # Python
diaspore-go run app.dsp.json              # Go
npx diaspore-ts run app.dsp.json          # TypeScript
lua5.4 runtimes/lua/cli.lua run app.dsp.json  # Lua

Features

  • Portable. One JSON artifact: diffable, signable, storable in a database column, validated before it runs.
  • Sandboxed. Network, file system and task spawning are denied unless granted. --max-steps caps CPU; exhausting it is an uncatchable trap.
  • Embeddable. Hosts expose functions as an importable module and call into the sandbox. Python, Go, TypeScript and Lua hosts share one model.
  • Durable. flow.suspend() pauses a program into a snapshot. Resume it later, in another process, on another runtime.
  • Self-hosted. The compiler is written in the subset it compiles. The Go and TypeScript runtimes embed it, so they build Python without Python, and so does the browser playground.
  • Conformant. Every corpus program must match CPython byte for byte on every runtime, backed by differential fuzzing.

Runtimes

Runtime Install Notes
diaspore-py uv tool install diaspore Reference VM, compiler and CLI
diaspore-go Release binaries; library: go get github.com/radkawar/diaspore/runtimes/go Near CPython speed; also compiles to WebAssembly
diaspore-ts npm install diaspore Node 22+, no runtime dependencies
diaspore-lua Release tarball Pure Lua 5.4; no tasks, regex or big integers

Sources: src/diaspore, runtimes/go, runtimes/ts, runtimes/lua.

Getting started

Install the compiler and reference runtime with uv:

uv tool install diaspore
diaspore build main.py -o main.dsp.json
diaspore run main.dsp.json

Run the same bundle from Node, or embed it:

npm install diaspore
npx diaspore-ts run main.dsp.json

To build everything from source you need Go 1.26+; Node 23.6+ and Lua 5.4 are needed only for their runtimes.

git clone https://github.com/radkawar/diaspore && cd diaspore
uv sync
make build    # embedded compiler + build/diaspore-go

Then try the examples, starting with embedding: one sandboxed plugin hosted from all four languages.

Embedding

from diaspore import Machine, compile_bundle

bundle = compile_bundle("plugin.py", extra_modules={"host"})
vm = Machine(bundle, bindings={"host": {"lookup": lookup}}, max_steps=1_000_000)
vm.run()
price = vm.call("plugin", "price", order)

The same pattern in Go, TypeScript and Lua.

Language

Functions, closures, classes with multiple inheritance, generators, async/await, exceptions including except*, match, comprehensions, f-strings, arbitrary-precision integers, multi-module packages, and a portable standard library (json, math, re, time, random, collections, itertools, functools and more). Unsupported syntax is a compile error with a file:line, never a silent runtime failure. The exact surface is in docs/spec.md.

Repository

src/diaspore/   compiler, reference VM, CLI, standard library
selfhost/       dspc, the self-hosted compiler
runtimes/       go, ts and lua runtimes
examples/       runnable examples for every runtime
site/           playground and project site
docs/           specification, security model, binary format
tests/          conformance corpus and test suites

Development

make test    # every suite on every runtime
make lint    # ruff, go vet, staticcheck, gofmt, tsc
make fuzz    # differential fuzzing against CPython
make serve   # build and serve the site on localhost:8000

Run make help for the full list.

License

MIT

Metadata

Release files for diaspore 0.2.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 diaspore 0.2.0
File Size Uploaded
diaspore-0.2.0.tar.gz 140.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for diaspore 0.2.0
File Interpreter ABI Platform
diaspore-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 273.4 kB

Release files / diaspore-0.2.0.tar.gz

Download URL diaspore-0.2.0.tar.gz
Size 140.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f67e07382aa2ea19335e5a28a3d8c38dd6b73b36b9667fe79c372ab7ae460169
BLAKE2b-256 checksum
How to use checksums
e5b9805828e54c26e358d905bcf6f3a1c65ed5008a74c8879c7abbe1597af5d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / diaspore-0.2.0-py3-none-any.whl

Download URL diaspore-0.2.0-py3-none-any.whl
Size 133.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4496a54c4320b92f6fc86e2a0f263032e57034aadd630233fac636f30ac355ef
BLAKE2b-256 checksum
How to use checksums
b9b7266335d1513c7707844c6da3e5c180e0bd5aee6f56a924ea464f6777febc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

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