Skip to main content

Module python_sandbox

Module python_sandbox 

Source
Expand description

Modern Python Plugin Runtime

AI-era design for running Python plugins in SochDB using:

  • Pyodide: Full CPython 3.12 with numpy, pandas, scikit-learn
  • WASM Component Model: Standard interfaces for cross-language composition
  • AI Triggers: Natural language → Python code generation

§Architecture

┌──────────────────────────────────────────────────────────┐
│                  Python Plugin System                     │
├──────────────────────────────────────────────────────────┤
│  PythonPlugin → PyodideRuntime → WASM Sandbox            │
│       ↓              ↓                ↓                  │
│   packages:      micropip          Memory isolation      │
│   numpy,pandas   install           Resource metering     │
└──────────────────────────────────────────────────────────┘

§Example

let runtime = PyodideRuntime::new(RuntimeConfig::default()).await?;
runtime.install_packages(&["numpy", "pandas"]).await?;

let plugin = PythonPlugin::new("fraud_detector")
    .with_code(r#"
        import numpy as np
        def on_insert(row):
            if row["amount"] > 10000:
                raise TriggerAbort("Amount too high")
            return row
    "#)
    .with_trigger("transactions", TriggerEvent::BeforeInsert);

runtime.register(plugin)?;

Structs§

AiTriggerGenerator
Generates Python trigger code from natural language instructions
PyodideRuntime
Pyodide-based Python runtime
PythonPlugin
A Python plugin with code and trigger bindings
RuntimeConfig
Configuration for the Pyodide runtime
RuntimeStats
Runtime statistics
TriggerContext
Context passed to trigger execution

Enums§

TriggerEvent
Types of trigger events
TriggerResult
Result from trigger execution