Call code from other language runtimes transparently - use Python's pandas from TypeScript, or TypeScript's fs module from Ruby.
Forthic enables cross-runtime execution where code in one language can seamlessly call modules and functions from another language runtime. This allows you to:
- Use Python's data science libraries (pandas, numpy) from TypeScript
- Call TypeScript's Node.js file operations from Python workflows
- Access Ruby Rails business logic from browser JavaScript
- Compose operations across multiple language services
import { Interpreter } from '@forthix/forthic'; import { JsonRpcClient, RemoteModule } from '@forthix/forthic/jsonrpc'; const interp = new Interpreter(); // Connect to Python runtime const client = new JsonRpcClient('localhost:8765'); const pandas = new RemoteModule('pandas', client, 'python'); await pandas.initialize(); interp.register_module(pandas); // Now use Python pandas from TypeScript! await interp.run(` ["pandas"] USE-MODULES # Create data in TypeScript, process in Python [ [["name" "Alice"] ["age" 30]] REC [["name" "Bob"] ["age" 25]] REC ] DF-FROM-RECORDS # Runs in Python! `); const df = interp.stack_pop(); // pandas DataFrame
Perfect for:
- Using specialized libraries not available in your primary language
- Gradual migration between languages
- Microservices that need to share logic
- Browser apps calling server-side operations
- Data pipelines spanning multiple technologies
Use cases:
- Data Science: Call Python pandas/numpy from TypeScript web app
- Web Apps: Call Rails business logic from browser Forthic code
- Microservices: Compose operations across Java, Python, Ruby services
Best for: Node.js ↔ Python ↔ Ruby communication
Advantages:
- No native dependencies — Node's built-in
httpplus globalfetch - Loopback-only bind and bearer-token auth by default
- Works between backend services
Requirements:
- Node.js ≥ 18 (not browser)
See: JSON-RPC Guide
Best for: Browser ↔ Rails communication
Advantages:
- Browser-compatible
- Built-in reconnection
- Progress updates for long operations
- Works with Rails ActionCable
Requirements:
- WebSocket support (built into browsers)
- ActionCable server (Rails)
See: WebSocket Guide
| Feature | JSON-RPC | WebSocket |
|---|---|---|
| Environment | Node.js only | Node.js + Browser |
| Use case | Server ↔ Server | Browser ↔ Server |
| Streaming | Request/response | Server → Client |
| Setup | Easy | Easy |
Decision guide:
- Running in browser? → Use WebSocket
- Server-to-server? → Use JSON-RPC
- Using a Rails backend? → Use WebSocket (ActionCable)
Note: A gRPC transport existed through v0.15.0 and was removed in v0.16.0. JSON-RPC is the supported server-to-server transport.
| Runtime | Status | JSON-RPC | WebSocket | Notes |
|---|---|---|---|---|
| TypeScript | ✅ Available | Client + Server | Client + Server | Full support |
| Python | ✅ Available | Client + Server | - | JSON-RPC only |
| Ruby | ✅ Available | Client + Server | Server (ActionCable) | Rails integration |
| Rust | 🚧 In Development | In progress | - | Coming soon |
| Java | 📋 Planned | - | - | Future |
| .NET | 📋 Planned | - | - | Future |
- For server-to-server: JSON-RPC Setup
- For browser-to-server: WebSocket Setup
See Configuration Guide for:
- YAML configuration files
- Runtime connection settings
- Module specifications
- Environment-specific configs
Check out working examples:
- examples/05-jsonrpc-server.ts - Expose TypeScript via JSON-RPC
- examples/06-jsonrpc-client.ts - Call Python from TypeScript
┌─────────────┐ ┌─────────────┐
│ TypeScript │ │ Python │
│ Runtime │ │ Runtime │
│ │ │ │
│ ┌───────┐ │ JSON-RPC / WebSocket │ ┌───────┐ │
│ │pandas │◄─┼────────────────────────┼──│pandas │ │
│ │remote │ │ │ │module │ │
│ └───────┘ │ │ └───────┘ │
│ │ │ │
│ Interpreter │ │ Interpreter │
└─────────────┘ └─────────────┘
Process:
- TypeScript client discovers available modules from remote runtime
- Creates local proxy module with same words
- When word is called, request sent to remote runtime
- Remote runtime executes word and returns result
- Result automatically deserialized back to TypeScript
All Forthic types are automatically serialized across runtimes:
- Primitives:
null,boolean,integer,float,string - Collections:
array,record(nested supported) - Temporal:
Instant,PlainDate,PlainTime,ZonedDateTime
Type conversion is automatic and transparent.
- JSON-RPC Guide - Server and client setup for Node.js
- WebSocket Guide - Browser-compatible communication
- Configuration - YAML config and connection management
- Examples - Working code samples
Multi-runtime communication uses versioned protocols:
- v1 Protocol: Current stable version
- JSON-RPC 2.0 over HTTP, and JSON over WebSocket
- Issues: Report problems
- Discussions: Ask questions
- Main Docs: Forthic repository