API Reference
MetaFFI provides language-specific APIs that share the same structure across all supported languages:
MetaFFIRuntime— Load a foreign language runtime into the processMetaFFIModule— Load a foreign module (JAR,.pyfile, compiled.dll/.so)load/load_entity— Load a specific entity (function, method, field) and get back a callable
Language APIs
| Language | API | Install |
|---|---|---|
| Python3 | MetaFFIRuntime, MetaFFIModule |
pip install metaffi-api |
| JVM | MetaFFIRuntime, MetaFFIModule, Caller |
metaffi.api.jar (ships with installer) |
| Go | MetaFFIRuntime, MetaFFIModule |
go get github.com/MetaFFI/sdk/api/go |
Common Pattern
All three APIs follow the same pattern:
1. Create runtime → MetaFFIRuntime("openjdk")
2. Load module → runtime.load_module("mylib.jar")
3. Load entity → module.load_entity("class=...,callable=...", params, retvals)
4. Call it → result = entity(args...)
5. Release → runtime.release_runtime_plugin()
The Entity Path documentation describes how to specify the location of entities within each language’s modules.
Two Usage Modes
MetaFFI offers two ways to call foreign code:
Dynamic API Calls
Use the API directly — load a runtime, load a module, load an entity by its entity path, and call it. This is the pattern shown above and throughout the Examples page.
Best for: exploration, quick scripts, prototyping.
Generated Wrappers (Host Compiler)
Use the host compiler to generate typed wrappers that call the API for you. The generated module exposes normal typed functions — no entity paths or type arrays in your application code.
metaffi -c --idl hello.go -h python3
import hello_MetaFFIHost as hello
hello.bind_module_to_code("hello_MetaFFIGuest", "go")
result = hello.SayHello("Python")
Best for: production codebases, large projects, CI.
Generated wrappers do not change runtime overhead — they wrap the same API calls shown above. See the Host Compiler page for details.