Skip to main content

DSPy CodeInterpreter implementation using Monty, a secure Python interpreter written in Rust

Project description

dspy-monty-interpreter

DSPy CodeInterpreter implementation using Monty, a secure Python interpreter written in Rust.

The Monty team points out, "This project is still in development, and not ready for the prime time." It uses a small subset of the standard library (sys, os, typing, asyncio, re, datetime, json, math) and can't yet define classes or use match statements. It does support with/context managers and a sandboxed open() (file access is opt-in via the mounts and os_access parameters).

That said: Monty is fast. For many RLM use cases, Monty is my daily driver.

Installation

pip install dspy-monty-interpreter

Requires pydantic-monty>=0.0.18.

Usage

import dspy
from dspy_monty_interpreter import MontyInterpreter

interpreter = MontyInterpreter()
rlm = dspy.RLM("context -> answer", interpreter=interpreter)
result = rlm(context="What is 2 + 2?")

Standalone usage

from dspy_monty_interpreter import MontyInterpreter

interp = MontyInterpreter()

# Basic execution
interp.execute("x = 42")
interp.execute("print(x + 8)")  # returns "50"

# State persists across calls
interp.execute("def double(n):\n    return n * 2")
interp.execute("double(21)")  # returns "42"

# With tools
def lookup(key: str) -> str:
    return "some value"

interp = MontyInterpreter(tools={"lookup": lookup})
interp.execute('result = lookup(key="foo")\nprint(result)')

Why Monty?

  • Fast: Microsecond startup (no subprocess, no WASM bootstrap)
  • Secure: No filesystem, network, or environment access by default
  • Lightweight: Pure Rust, no Deno/Pyodide dependency

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

dspy_monty_interpreter-0.2.6.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

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

dspy_monty_interpreter-0.2.6-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file dspy_monty_interpreter-0.2.6.tar.gz.

File metadata

  • Download URL: dspy_monty_interpreter-0.2.6.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for dspy_monty_interpreter-0.2.6.tar.gz
Algorithm Hash digest
SHA256 b17f7182f5010f884077cdd1b7a57f41bd3c47937115bd9d27ca479b6447c3f7
MD5 796bd8a80da6d579d7b9c7c38310d29f
BLAKE2b-256 558ba7d7ea848c55e3547dbb260323b8a1e8a86ad56b099d6a461d265091c895

See more details on using hashes here.

File details

Details for the file dspy_monty_interpreter-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for dspy_monty_interpreter-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4eaf1004290e8b88b8a4004d5b7a1ea79aa4ea82a73d0c035821c6e913324e8d
MD5 85565fc7160e7f14b087c22fdee554ab
BLAKE2b-256 012606842ad20ea92fe0417496b7001d0d39735ba3f4554ba31694d6d4c7ef47

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