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

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
MontyResult Execution result with value, error, and resource usage
MontyProgress Sealed type: MontyPending (awaiting external call) or MontyComplete
MontyLimits Resource constraints (timeout, memory, stack depth)
MontyException Python error with message, filename, line/column
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.