View on GitHub

Dapy: distributed algorithms in Python

Simulate, prototype, and visualize distributed algorithms.

πŸš€ Dapy: Simulating Distributed Algorithms in Python

Dapy logo

Dapy is a lightweight Python framework for prototyping, simulating, and visualizing distributed algorithms in a controlled environment. Perfect for education, research, and experimentation with distributed computing concepts.

What is Dapy?

Dapy provides:

Whether you’re teaching distributed computing or exploring new algorithms, Dapy streamlines the prototyping process.

Two Components

Dapy is split into two independent parts:


🎯 Quick Start

Installation

Dapy is currently under active development and not yet published on PyPI.

Recommended: Use the Template Repository

The fastest way to get started is using our project template:

  1. Get the template:
    • Download the template or copy it from the dapy repository
    • It includes pre-configured project structure, example algorithm, and ready-to-use setup
  2. Install dependencies:
    cd my-algorithm-project
    uv sync
    
  3. Run the example:
    uv run run-bcast
    dapyview              # Opens file selector, or:
    dapyview traces/broadcast_trace.pkl
    

See the template README for complete instructions.

Alternative: Install dapy as a dependency

For existing projects, install dapy directly from GitHub:

# Using uv (recommended)
uv add "dapy @ git+https://github.com/xdefago/dapy.git"

# Or using pip
pip install "git+https://github.com/xdefago/dapy.git"

This installs:

For dapy developers who want to modify dapy itself:

See the Developer Documentation for setup with editable install.

Your First Algorithm

from dapy.core import Algorithm, State, Message, Pid
from dataclasses import dataclass

@dataclass(frozen=True)
class MyState(State):
    received: bool = False

class SimpleAlgorithm(Algorithm):
    def get_initial_state(self, pid: Pid, **kwargs) -> MyState:
        return MyState(received=False)
    
    def on_init(self, state, pid, topology, message_pool):
        if pid == 0:
            message_pool.add_message(message=str("hello"), sender=0, receiver=1)
    
    def on_message(self, state, msg, sender):
        return state.__class__(received=True)

Visualize Your Trace

  1. Run your algorithm and save a trace
  2. Open the trace with Dapyview:
    dapyview              # Opens file selector
    dapyview trace.pkl    # Opens specific file
    
  3. Explore message flows, causality relationships, and timing

πŸ“š Documentation

For Users

For Developers


🎨 Dapyview: Visual Trace Viewer

Dapyview is an interactive GUI for visualizing execution traces of distributed algorithms.

Key Features

Getting Started with Dapyview

# Run dapyview with a trace file
dapyview examples/sample_trace.json

# Or start without a file (open via menu)
dapyview

See the Dapyview User Guide for detailed documentation.


πŸ—οΈ Project Structure

dapy/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ dapy/           # Main framework
β”‚   β”‚   β”œβ”€β”€ core/       # Core abstractions (Algorithm, State, Message, etc.)
β”‚   β”‚   β”œβ”€β”€ sim/        # Simulation engine
β”‚   β”‚   └── algo/       # Example algorithms
β”‚   └── dapyview/       # GUI trace viewer (optional)
β”œβ”€β”€ examples/           # Example algorithms and traces
β”œβ”€β”€ tests/              # Test suite
β”œβ”€β”€ docs/               # This documentation
└── pyproject.toml      # Project configuration

πŸ” Features at a Glance

Feature Description
Algorithm Abstraction Simple API for defining distributed algorithms
Deterministic Simulation Repeatable execution for consistent debugging
Message Traces Complete records of all communication and events
Causality Analysis Vector clock-based causal relationships
Interactive Visualization Dapyview GUI with time-space diagrams
Educational Focus Designed for teaching distributed computing

πŸ’‘ Use Cases


πŸ“– More Information


🀝 Contributing

Interested in contributing? We welcome:

Check the repository for contribution guidelines.


Start simulating your distributed algorithms today!