Portalis - Python to Rust/WASM Transpiler

raw JSON →
0.1.6 verified Fri May 01 auth: no javascript

Portalis is a production-ready platform (v0.1.6) that translates Python codebases into Rust and compiles them to WebAssembly, featuring CPU SIMD optimization (AVX2, SSE4.2, NEON) and optional GPU acceleration via CUDA. Built on the Wassette runtime, it delivers up to 7.8× speedup through arena allocation, string interning, and object pooling. Supports Python 3.11+, Rust 1.75+, and outputs WASM, native binaries, or libraries. Released as an npm package (Node >=14.0.0) and cargo crate. Differentiators over similar tools include multi-tier acceleration, enterprise features (RBAC, SSO), and a complete pipeline with agent swarm architecture. Currently in active development with 137 tests and 35k+ LOC.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/portalis/index.js not supported.
cause Portalis is ESM-only; using require() instead of import.
fix
Use import statement or dynamic import(). If using CommonJS, consider dynamic import: const portalis = await import('portalis');
error TypeError: Cannot read properties of undefined (reading 'factorial')
cause Trying to call an exported function before the WASM instance is fully initialized.
fix
Ensure runtime.load() is awaited and the module exports are accessed after the promise resolves.
error error[portalis]: GPU acceleration requires CUDA toolkit and NVIDIA GPU. Set 'gpu: false' to disable.
cause CUDA environment not set up but GPU option enabled.
fix
Install CUDA toolkit and drivers, or disable GPU: { gpu: false }.
error SyntaxError: Unexpected token 'export'
cause Trying to run Portalis in a CommonJS context without proper module system.
fix
Use ESM: add "type": "module" in package.json or rename to .mjs.
gotcha Portalis is ESM-only; requires Node >=14.0.0 and 'type': 'module' in package.json or .mjs extension.
fix Add "type": "module" to package.json or rename files to .mjs.
gotcha GPU acceleration (CUDA) is optional and requires NVIDIA drivers, CUDA toolkit, and explicit enabling via options.gpu: true.
fix Set { gpu: true } in translate/compile options and ensure CUDA environment is configured.
breaking WassetteRuntime moved from 'portalis' to 'portalis/runtime' in v0.1.4; imports from the main entry will fail.
fix Update import to 'portalis/runtime'.
gotcha SIMD optimizations (AVX2/NEON) are enabled by default but may cause issues in non-native environments (e.g., some cloud containers). Disable with { simd: false }.
fix Pass { simd: false } to translate or compile options.
deprecated The 'wasm' output format uses the old Wassette v1 runtime; v2 is in preview and activated via { runtimeVersion: 2 }.
fix For new projects, set { runtimeVersion: 2 } to use the preview Wassette v2 runtime.
npm install portalis
yarn add portalis
pnpm add portalis

Demonstrates Python-to-WASM pipeline: translate Python factorial function to Rust, compile to WASM with SIMD, and execute using WassetteRuntime.

import { translate, compile } from 'portalis';

async function main() {
  // Translate Python code to Rust source
  const rustCode = await translate(`
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n-1)
`, { target: 'wasm' });
  console.log('Generated Rust:', rustCode);

  // Compile to WebAssembly binary
  const wasmBuffer = await compile(rustCode, {
    optimization: 'speed',
    simd: true,
    gpu: false
  });
  console.log('WASM binary size:', wasmBuffer.length, 'bytes');

  // Execute in Wassette runtime
  const { WassetteRuntime } = await import('portalis/runtime');
  const runtime = new WassetteRuntime();
  const instance = await runtime.load(wasmBuffer);
  const result = instance.exports.factorial(10);
  console.log('factorial(10):', result);
}

main().catch(console.error);