Skip to main content

Orchestrator for mrmd services - starts sync, monitors, and runtimes

Project description

mrmd-orchestrator

Python orchestrator for mrmd services. Starts and manages sync server, monitors, and runtimes.

Quick Start

# From mrmd-packages directory
cd mrmd-orchestrator

# Create virtual environment and install dependencies with uv
uv venv
uv pip install -e .

# Start everything
uv run mrmd

# Or with options
uv run mrmd --docs ./notebooks --port 3000

Then open http://localhost:8080/examples/minimal.html

What It Does

The orchestrator:

  1. Starts mrmd-sync - Yjs sync server on ws://localhost:4444
  2. Starts mrmd-python - Python runtime on http://localhost:8000
  3. Serves mrmd-editor - Static files on http://localhost:8080
  4. Manages monitors - Start/stop via HTTP API
┌─────────────────────────────────────────────────────────────────┐
│  mrmd-orchestrator (Python)                                     │
│                                                                 │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐            │
│  │ mrmd-sync   │  │ mrmd-python │  │ HTTP Server │            │
│  │ (Node.js)   │  │ (Python)    │  │ + API       │            │
│  │ port 4444   │  │ port 8000   │  │ port 8080   │            │
│  └─────────────┘  └─────────────┘  └─────────────┘            │
│         │                                   │                   │
│         └──── monitors (per document) ──────┘                   │
│               ┌─────────┐ ┌─────────┐                          │
│               │monitor:a│ │monitor:b│ ...                      │
│               └─────────┘ └─────────┘                          │
└─────────────────────────────────────────────────────────────────┘

CLI Options

mrmd [options]

Paths:
  --docs, -d PATH        Document directory (default: ./docs)
  --packages PATH        Path to mrmd-packages (auto-detected)

Ports:
  --port, -p PORT        HTTP/API port (default: 8080)
  --sync-port PORT       Sync server port (default: 4444)
  --runtime-port PORT    Python runtime port (default: 8000)

Remote Services (distributed mode):
  --sync-url URL         Connect to existing sync server
  --runtime-url URL      Connect to existing runtime

Disable Services:
  --no-sync              Don't start mrmd-sync
  --no-runtime           Don't start mrmd-python
  --no-editor            Don't serve editor files
  --no-monitors          Don't allow starting monitors

Auto-start:
  --monitor DOC          Auto-start monitor for document (repeatable)

Examples:
  mrmd                                    # Start everything
  mrmd --docs ./notebooks                 # Custom docs directory
  mrmd --monitor my-notebook              # Auto-start monitor
  mrmd --sync-url ws://remote:4444        # Use remote sync

HTTP API

Status

# Health check
GET /health

# Full status
GET /api/status

# Service URLs
GET /api/urls

Monitors

# List active monitors
GET /api/monitors

# Start monitor for document
POST /api/monitors
Content-Type: application/json
{"doc": "my-notebook"}

# Stop monitor
DELETE /api/monitors/my-notebook

# Check monitor status
GET /api/monitors/my-notebook

Logs

# Get recent output from a process
GET /api/logs/mrmd-sync?lines=100
GET /api/logs/mrmd-python?lines=50
GET /api/logs/monitor:my-notebook?lines=50

Distributed Mode

For users who want services on different machines:

# Machine 1: Sync server only
cd mrmd-sync && node bin/cli.js ./docs

# Machine 2: Python runtime only
cd mrmd-python && python -m mrmd_python.cli --port 8000

# Machine 3: Orchestrator connecting to remote services
mrmd \
  --sync-url ws://machine1:4444 \
  --runtime-url http://machine2:8000/mrp/v1 \
  --no-sync \
  --no-runtime

Or use the Python API:

from mrmd_orchestrator import Orchestrator, OrchestratorConfig

config = OrchestratorConfig.for_distributed(
    sync_url="ws://remote-sync:4444",
    runtime_urls={"python": "http://remote-python:8000/mrp/v1"},
)

orchestrator = Orchestrator(config)
await orchestrator.start()

Programmatic Usage

import asyncio
from mrmd_orchestrator import Orchestrator, OrchestratorConfig

async def main():
    # Default config (start everything locally)
    config = OrchestratorConfig.for_development()

    # Create orchestrator
    orchestrator = Orchestrator(config)

    # Start services
    await orchestrator.start()

    # Start a monitor
    await orchestrator.start_monitor("my-notebook")

    # Check status
    status = orchestrator.get_status()
    print(status)

    # Stop monitor
    await orchestrator.stop_monitor("my-notebook")

    # Stop everything
    await orchestrator.stop()

asyncio.run(main())

Architecture: 1 Monitor Per Document

Each document gets its own monitor process:

Document A ──→ monitor:document-a ──→ mrmd-python (session: document-a)
Document B ──→ monitor:document-b ──→ mrmd-python (session: document-b)

Why?

  • Isolation: Killing notebook A doesn't affect B
  • Matches mental model: "Restart" means this notebook
  • Security: Different permissions per notebook
  • Matches Jupyter: 1 kernel per notebook

Trade-offs:

  • More processes (10 notebooks = 10 monitors)
  • Startup latency when opening new documents

Development

# Create venv and install with dev dependencies
cd mrmd-orchestrator
uv venv
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Run with debug logging
uv run mrmd --log-level debug

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrmd_orchestrator-0.1.1.tar.gz (100.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrmd_orchestrator-0.1.1-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file mrmd_orchestrator-0.1.1.tar.gz.

File metadata

  • Download URL: mrmd_orchestrator-0.1.1.tar.gz
  • Upload date:
  • Size: 100.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mrmd_orchestrator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2bd469f29bdfb4a817ae764b8d72da27c8fdfb4c1989152320c99d81d6ec52ff
MD5 fca06b4e6d9e738367fda0b10be72226
BLAKE2b-256 cb3b0cc0f06df2f04c25ac3b3d0ed60eba1a882beca6b368ceb9beb756268883

See more details on using hashes here.

File details

Details for the file mrmd_orchestrator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mrmd_orchestrator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b69a4b9f32a623a3789b1d774b182eab9f005fae205bb7024a507b580f3c5d88
MD5 6f6d5bf6695156dcba2c055e24bcedae
BLAKE2b-256 77f07819c9993dc92f18e267cb73c3491d79a1d34a153ac855031aaa3b031afe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page