Skip to content

KlorPy

Choreographic programming for Python.

An embedded domain-specific language that lets you write one global program — a choreography describing the roles in a distributed system and how values move between them — and have KlorPy project it into a deadlock-free endpoint program for each role.

from klorpy import choreography, move, simulate_chor, A, B

@choreography
def ping_pong(x):
    y = move(x, A, B)   # send x from A to B; the result lives at B
    return y

simulate_chor(ping_pong, {"x": 42})
# => {'A': NOOP, 'B': 42}

Quote

Instead of writing one program per participant and manually threading messages, you write one choreography. KlorPy turns it into one program per role, with the communication already woven in — so the projections cannot deadlock or diverge.

This is a working vertical slice of the ideas behind Klor (Choreographies in Clojure), ported to Python without macros: inspect + ast + compile + asyncio do the work instead, and the transport layer is pluggable (in-memory simulator, or real TCP sockets).

What you get

  • One source, N roles. @choreography def … is analyzed, type-checked and projected into a per-role endpoint program at definition time.
  • Location-aware types. Every value knows where it lives; misuse is rejected at definition, not at runtime (see The model).
  • A simulator and a real network. Run all roles in one process with simulate_chor, or play one role against any transport — including the bundled TCP transport (see Networking (TCP)).
  • Fail-fast validation. Unsupported constructs raise clear errors at definition rather than miscompiling silently.

Where to go next