DEV Community

Cover image for I got tired of writing boilerplate imports, so I built Block: Run Python, JS, and Lua in a single file
O-O1112
O-O1112

Posted on

I got tired of writing boilerplate imports, so I built Block: Run Python, JS, and Lua in a single file

šŸ’” The Problem: The Import / Glue Code Headache

A while ago, I was practicing importing modules across different projects. I wanted to use Python for its rich data science libraries and Node.js for its async web performance.

Normally, if you want Python to pass a simple calculated array or dictionary to JavaScript, you have to:

  1. Spin up a local FastAPI / Flask server or write to a temporary JSON file.
  2. Setup fetch() in Node.js, handle ports, serialization, and CORS.
  3. Write 50+ lines of glue code just to share a single variable.

Coming from a visual block-coding mindset (where you snap blocks together and data flows naturally), I thought:

"Why can't I just write <py> and <js> in the exact same file, and let the variables flow automatically?"

So I built Block Engine.


⚔ How Block Works

In Block, you write native language blocks separated by tags (<py>, <js>, <lua>, <php>, <server>).

The underlying orchestrator (built with high-performance C# / .NET) automatically serializes and injects variables across runtime boundaries via an in-memory State Pipeline:

<py>
# Python stage: Prepare initial dataset
user = "O-O1112"
dataset = [10, 20, 30, 40, 50]
print(f"[Python] Loaded {len(dataset)} items for {user}")
</py>

<js>
// Node.js stage: High-performance aggregation
const avg = dataset.reduce((a, b) => a + b, 0) / dataset.length;
console.log(`[Node.js] Computed average: ${avg}`);
var bonus = 50;
</js>

<lua>
-- Lua stage: Lightning-fast validation
final_score = avg + bonus
print("[Lua] Final Computed Score: " .. tostring(final_score))
</lua>
Enter fullscreen mode Exit fullscreen mode

šŸŽÆ Running it:

block demo.blkp
Enter fullscreen mode Exit fullscreen mode

Output:

[Python] Loaded 5 items for O-O1112
[Node.js] Computed average: 30
[Lua] Final Computed Score: 80.0
āœ” State Pipeline synchronized across 3 runtimes in 320ms.
Enter fullscreen mode Exit fullscreen mode

šŸš€ Key Features

  • Zero-Glue State Pipeline: Variables declared in Python are instantly accessible in JS and Lua without manual JSON parsing.
  • Native Ecosystem Compatibility: Direct access to your existing host pip, npm, and luarocks libraries.
  • Zero-Install NPX Execution: You can run any .blkp file directly in terminal without manual installer setup:
  npx block-engine-runner demo.blkp
Enter fullscreen mode Exit fullscreen mode
  • Modular Imports: Supports <import src="modules/data.blk" /> and custom runtime definitions with <define lang="sim" cmd="node" />.
  • Open Source: Released under the MIT license.

šŸ”— Links & Resources

I would love to hear feedback and thoughts from the DEV community on this state-pipeline approach! What languages would you like to see chained next?

Top comments (1)

Collapse
 
alexshev profile image
Alex Shev

The multi-language single-file idea is interesting because it attacks setup friction directly. The risk is making execution rules feel implicit. I would want very visible boundaries around runtime, dependencies, and file access so a convenient block does not become surprising behavior.