Skip to main content

Diaspore

Diaspore compiles a large subset of Python into a portable JSON bundle for Python, Go, TypeScript and Lua runtimes. Bundles have no ambient filesystem or network authority and support fuel limits. Python, Go and TypeScript can pause execution into a JSON snapshot and resume it on another compatible runtime.

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

By default, bundles contain program code and a content hash identifying the standard library shipped by the runtime. The prebuilt stdlib.dsps (DSPS02) store loads only its compact index initially; standalone module DSPB payloads are checked, decoded and cached on demand. Python, Go and TypeScript compress each module with raw DEFLATE and a shared preset dictionary from the index; Lua ships raw payloads. Compression does not change the library's content hash. Imports initialize each machine's library modules only when needed. A mismatched library is rejected before execution. For an artifact that carries its own reachable library modules:

diaspore build app.py --self-contained -o app.dsp.json

compile_bundle(..., self_contained=True) provides the same option to Python embedders. Go, TypeScript and Lua compilers expose the corresponding option.

make generate produces matching stores for all four runtimes, including the Python package; runtime startup does not compile installed library sources. Index and per-module hashes detect corrupted artifacts, not malicious replacement of a distribution. See docs/dspb.md for the binary format.

Features

  • JSON bundles can be inspected, signed, and stored independently of their host.
  • Network, file system and task spawning are denied unless granted. --max-steps caps CPU; exhausting it is an uncatchable trap.
  • Hosts expose functions as an importable module and call into the sandbox. Python, Go, TypeScript and Lua hosts share one model.
  • flow.suspend() pauses a program into a snapshot on the Python, Go and TypeScript runtimes. Resume it later in another process or runtime.
  • The compiler is written in the subset it compiles. Go and TypeScript embed its compiled bundle; Lua loads it from the runtime installation. These runtimes and the browser playground build Python without Python installed.
  • Supported corpus programs are compared byte for byte with CPython, alongside differential fuzzing. Runtime-specific exclusions are documented in the specification and runtime READMEs.

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 Native binary and WebAssembly
diaspore-ts npm install diaspore Node 22+, no runtime dependencies
diaspore-lua Release tarball Pure Lua 5.4; arbitrary-precision integers, no tasks or network

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

Source builds require a POSIX host, GNU Make 4.3+, and 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
make vendor  # restore pinned CPython standard-library sources
make cpython # CPython regression scoreboard and pass-count ratchet

Run make help for the full list.

The API detector derives its cases from package source. The self-suite executes the package's pure tests inside the sandbox:

uv run --python 3.12 pytest -q tests/test_api_parity.py
uv run --python 3.12 pytest -q -rs tests/test_self_suite.py

make cpython records per-module outcomes in build/cpython-regressions/ and compares pass counts with tests/cpython_baseline.json. Compilation failures, import failures, skips, and unexecuted tests are distinct from passing tests. See tools/stdlib_manifest.json for the exact vendored module inventory.

License

MIT

The bundled pure-Python standard library includes unmodified files from CPython v3.12.12, distributed under the Python Software Foundation license and the notices in src/diaspore/cpython/LICENSE. Source distributions retain unmodified sources and their manifest in src/diaspore/cpython; Diaspore's maintained C-layer adapters and overlays live in src/diaspore/stdlib. Runtime packages ship precompiled code and notices. Compilers search the maintained root before the upstream root. Unicode property and identifier tables include data distributed under the Unicode License.

Metadata

Release files for diaspore 0.3.1

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.3.1
File Size Uploaded
diaspore-0.3.1.tar.gz 2.6 MB Details

Built distribution (wheel)

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

Total release size: 8.0 MB

Release files / diaspore-0.3.1.tar.gz

Download URL diaspore-0.3.1.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
dba56d534046963e48af61adfa1c43f6845dbf62e913f1e34fbdecc89f2d7e46
BLAKE2b-256 checksum
How to use checksums
32d396e830c7bcab649f3e8bd253808a6e12f9ce799cba7377078fbff1a99b6f
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.3.1-py3-none-any.whl

Download URL diaspore-0.3.1-py3-none-any.whl
Size 5.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5691ed306c7f96ebcd3bb4db7ab656f9134155002010567635277290d6f35b45
BLAKE2b-256 checksum
How to use checksums
61ce6983fd939129a28b398e2baec67ee6f6daf7e7bd90af07e471c61738bb7c
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

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

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