Skip to main content
Monty supports a carefully selected subset of Python 3.14 designed for agent code execution. This page documents the supported language features.

Supported Features

Monty can run a reasonable subset of Python code - enough for your agent to express what it wants to do.

Core Language Features

Monty supports standard Python function definitions including:
  • Function definitions with def
  • Async functions with async def
  • Positional and keyword arguments
  • Default parameter values
  • Return statements
  • Nested functions
def fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

async def fetch_data(url: str):
    data = await get_content(url)
    return data
Full support for Python control flow statements:
  • if, elif, else conditionals
  • while loops
  • for loops with iterators
  • break and continue statements
  • return statements
# Conditional logic
if x > 10:
    print('large')
elif x > 5:
    print('medium')
else:
    print('small')

# Loops
for item in items:
    if should_skip(item):
        continue
    process(item)
Monty supports common Python built-in types:
  • Primitives: int, float, bool, None
  • Strings: str with full Unicode support
  • Collections: list, tuple, dict, set
  • Functions: Function objects and lambdas
# All these types work in Monty
count = 42
ratio = 3.14
enabled = True
name = 'Alice'
items = [1, 2, 3]
config = {'host': 'localhost', 'port': 8080}
First-class support for asynchronous programming:
  • async def function definitions
  • await expressions
  • Coroutines and async generators
  • Integration with host event loop
async def agent(prompt: str, messages: list):
    while True:
        output = await call_llm(prompt, messages)
        if isinstance(output, str):
            return output
        messages.extend(output)
Full support for modern Python type hints:
  • Function parameter and return type annotations
  • Variable type annotations
  • Generic types from typing module
  • Built-in type checking with ty
from typing import List, Dict, Optional

def process(items: List[str]) -> Dict[str, int]:
    return {item: len(item) for item in items}

result: Optional[str] = None
Standard Python operators are supported:
  • Arithmetic: +, -, *, /, //, %, **
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: and, or, not
  • Membership: in, not in
  • Identity: is, is not
result = (x + y) * 2
if name in allowed_names and count > 0:
    process()
All Python comprehension types:
  • List comprehensions
  • Dict comprehensions
  • Set comprehensions
  • Generator expressions
squares = [x**2 for x in range(10) if x % 2 == 0]
lookup = {name: len(name) for name in names}
unique = {word.lower() for word in words}
total = sum(x for x in numbers if x > 0)
Full exception handling support:
  • try/except/finally blocks
  • raise statements
  • Built-in exception types
  • Custom exception messages
try:
    result = risky_operation()
except ValueError as e:
    print(f'Invalid value: {e}')
except Exception:
    raise RuntimeError('Operation failed')
finally:
    cleanup()
Multiple string formatting options:
  • f-strings with expressions
  • .format() method
  • % formatting
  • String concatenation
# f-strings (recommended)
message = f'Hello {name}, you have {count} items'

# .format() method
template = 'Status: {status}'
result = template.format(status='ready')

Built-in Functions

Monty provides access to essential Python built-in functions:
  • Type conversions: int(), str(), float(), bool(), list(), dict(), set(), tuple()
  • Iteration: len(), range(), enumerate(), zip(), iter(), next()
  • Functional: map(), filter(), sorted(), sum(), min(), max(), any(), all()
  • I/O: print() (output captured by host)
  • Inspection: type(), isinstance(), hasattr(), getattr(), setattr()
  • Other: abs(), round(), repr(), id()
# Built-in functions work as expected
print('Processing items...')
numbers = list(range(10))
filtered = [x for x in numbers if x % 2 == 0]
total = sum(filtered)
print(f'Sum of evens: {total}')
Monty’s print() function captures output and returns it to the host via callbacks, rather than writing directly to stdout.

Performance Characteristics

Monty provides excellent performance for agent workloads:
  • Startup time: <1μs from code to execution result
  • Runtime performance: Generally between 5x faster and 5x slower than CPython
  • Memory efficiency: Manual reference counting and controlled allocation
  • Resource limits: Built-in tracking of memory, allocations, and execution time

Next Steps

Standard Library

Explore supported stdlib modules like sys, os, typing, and asyncio

Limitations

Understand what Python features are not supported

Build docs developers (and LLMs) love