Skip to main content

Python runtime server implementing the MRMD Runtime Protocol (MRP)

Project description

mrmd-python

Independent Python runtime for MRMD notebooks. Runs as a daemon process with full GPU memory isolation.

Features

  • Independent daemon process - survives if parent dies, variables persist
  • GPU memory isolation - kill daemon to release VRAM (critical for vLLM)
  • Auto venv detection - uses current venv or VIRTUAL_ENV
  • Registry-based discovery - find runtimes via ~/.mrmd/runtimes/
  • Full MRP protocol - execute, completions, inspect, variables, streaming

Installation

# With uv
uv pip install mrmd-python

# Or run directly without installing
uvx mrmd-python

Quick Start

# Start a daemon runtime (auto-detects venv)
mrmd-python

# The daemon runs in background. Use the API:
curl http://localhost:PORT/mrp/v1/capabilities

# List running runtimes
mrmd-python --list

# Kill when done (releases GPU memory)
mrmd-python --kill default

CLI Reference

# Start daemon
mrmd-python                     # Start with ID "default"
mrmd-python --id vllm           # Start with custom ID
mrmd-python --venv /path/venv   # Use specific venv
mrmd-python --port 8000         # Use specific port

# Management
mrmd-python --list              # List all running runtimes
mrmd-python --info ID           # Get runtime details
mrmd-python --kill ID           # Kill a runtime
mrmd-python --kill-all          # Kill all runtimes

# Development
mrmd-python --foreground        # Run in foreground (no daemon)

Virtual Environment Detection

When --venv is not specified, mrmd-python auto-detects:

  1. Current venv (if running inside one via sys.prefix)
  2. VIRTUAL_ENV environment variable
  3. Falls back to system Python

API Endpoints

All endpoints at /mrp/v1/:

Endpoint Method Purpose
/capabilities GET Runtime info and features
/sessions GET/POST List/create sessions
/sessions/{id} GET/DELETE Get/destroy session
/execute POST Run code
/execute/stream POST Run code with SSE streaming
/complete POST Get completions
/inspect POST Get symbol documentation
/hover POST Get hover tooltip
/variables POST List user variables
/variables/{name} POST Get variable details
/is_complete POST Check if code is complete
/format POST Format code with black

Architecture

~/.mrmd/
├── runtimes/
│   └── {id}.json    # Registry: pid, port, url, venv, cwd
└── logs/
    └── {id}.log     # Daemon logs

Each runtime is a fully independent process:

  • Double-forked daemon (survives parent death)
  • Own IPython shell with persistent variables
  • HTTP server on auto-assigned port
  • Registered in ~/.mrmd/runtimes/ for discovery

GPU Memory Management

For vLLM and other GPU workloads, memory is only released when the process dies:

# Load model in runtime
mrmd-python --id vllm
# ... use the model ...

# Release GPU memory
mrmd-python --kill vllm

Programmatic Usage

from mrmd_python import create_app
import uvicorn

# Create app (daemon_mode=True for use inside daemon)
app = create_app(
    cwd="/path/to/project",
    venv="/path/to/venv",
    daemon_mode=True,
)
uvicorn.run(app, host="localhost", port=8000)

Protocol

See PROTOCOL.md for the full MRP specification.

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_python-0.3.4.tar.gz (55.7 kB view details)

Uploaded Source

Built Distribution

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

mrmd_python-0.3.4-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file mrmd_python-0.3.4.tar.gz.

File metadata

  • Download URL: mrmd_python-0.3.4.tar.gz
  • Upload date:
  • Size: 55.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for mrmd_python-0.3.4.tar.gz
Algorithm Hash digest
SHA256 cefb153d688a36253498c678e1151e474f7ce47c7c7e05360220023ffe27aefd
MD5 82b281ea6b76b2edc1dd5e0d340724f1
BLAKE2b-256 61b658805c802493e7de1cf4ec23ce1e1ab46295f40075205c9c1ee5859b289a

See more details on using hashes here.

File details

Details for the file mrmd_python-0.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mrmd_python-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 691bb1fd4bc3dcb591cbb7b4dda37adff99b49b49633c5360c789e118d924d74
MD5 e02123366fc2ef3cef863cbea1c2659f
BLAKE2b-256 e58a11b94c78042f505d124d56f2d949d72398dfd01be9724b2a0b00d4aa4309

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