dart_monty_platform_interface

Part of dart_monty — pure Dart bindings for Monty, a restricted, sandboxed Python interpreter built in Rust.

Live Demo | GitHub | Monty

Bob 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.

  • Flutter apps should import dart_monty instead — the federated plugin selects the correct backend automatically.
  • Pure Dart projects (CLI, server) can depend on this package directly alongside dart_monty_ffi or dart_monty_wasm.

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.

Libraries

dart_monty_platform_interface
Platform interface for dart_monty.
dart_monty_testing
Testing utilities for dart_monty.
monty_backend_spi
Service Provider Interface for dart_monty platform backends.