dart_monty_platform_interface 0.8.0
dart_monty_platform_interface: ^0.8.0 copied to clipboard
Platform interface for dart_monty, pure Dart bindings for Monty — a restricted sandboxed Python interpreter built in Rust.
dart_monty_platform_interface #
Part of dart_monty — pure Dart bindings for Monty, a restricted, sandboxed Python interpreter built in Rust.
This package is co-designed by human and AI — nearly all code is AI-generated.
Pure Dart platform interface for dart_monty. Defines the shared API contract (MontyPlatform) implemented by native and web backends, along with common types like MontyResult, MontyException, and MontyResourceUsage.
This package has no Flutter dependency and can be used in CLI tools, server-side Dart, or any Dart project.
- Most users should import
dart_montyinstead — it selects the native or web backend at compile time via conditional imports. - Direct usage is for backend implementers or projects that need fine-grained type access.
Key Types #
| Type | Description |
|---|---|
MontyPlatform |
Abstract contract for running Python code |
BaseMontyPlatform |
Shared translation logic with MontyCoreBindings adapter |
MontyResult |
Execution result with value, error, and resource usage |
MontyProgress |
Sealed type: MontyPending (awaiting external call) or MontyComplete |
MontyError |
Sealed error hierarchy: MontyCancelledError, MontyScriptError, MontyPanicError, MontyCrashError, MontyDisposedError, MontyResourceError |
MontyCancelToken |
Extension type for cross-isolate cancellation via cancelById/isHandleAlive |
MontySession |
Stateful session with snapshot/restore under the hood |
MontyLimits |
Resource constraints (timeout, memory, stack depth) |
MontyException |
Python error with message, filename, line/column, traceback |
MontyResourceUsage |
Memory, time, and stack depth statistics |
Usage #
import 'package:dart_monty_platform_interface/dart_monty_platform_interface.dart';
// Construct a result from JSON (as returned by native/web backends).
final result = MontyResult.fromJson({
'value': 42,
'usage': {
'memory_bytes_used': 1024,
'time_elapsed_ms': 5,
'stack_depth_used': 2,
},
});
print(result.value); // 42
print(result.usage.memoryBytesUsed); // 1024
See the main dart_monty repository for full documentation.