Code Samples
Elide is a single binary that is two things at once: a polyglot runtime
(JavaScript, TypeScript, Python, and the JVM) and a complete toolchain
(compilers, a code formatter, a package installer, and a server). Every example
below uses only that one binary -- there is no Node, no python, no JDK, and no
build tool to install alongside it.
Each section states a real problem, shows the code, shows the exact command, and shows the output. If you only have five minutes, read the formatter section -- it is the feature most teams reach for first.
Run any language, no build step
Elide picks a language from the file extension. There is nothing to configure and nothing to compile first.
// discount.ts
interface Order {
item: string;
price: number;
qty: number;
}
function total(order: Order): number {
return order.price * order.qty;
}
const order: Order = { item: "keyboard", price: 79.99, qty: 2 };
console.log(`${order.item}: ${total(order).toFixed(2)}`); elide discount.tskeyboard: $159.98That file is TypeScript with real type annotations, and it ran directly. Elide
strips the types at native speed (via OXC) and executes the
result -- there is no tsconfig.json and no transpile step. The same is true
for .js, .mjs, and .py files.
Because the runtime is introspectable, you can ask Elide about itself from guest
code through the global Elide object:
// about.js
console.log("Elide", Elide.version);
console.log("- build mode:", Elide.buildMode);
console.log("- target:", Elide.targetArchitecture); elide about.jsSee Getting Started for the language-detection rules, and Elide + Web for the JS/TS runtime details.
Format Java and Kotlin with one command
This is Elide's most immediately useful tool. elide fmt (aliased as
elide format) is a single, unified formatter for both Java and Kotlin. It
embeds Google Java Format and
ktfmt, compiled ahead-of-time with native
image, so it starts in milliseconds instead of paying JVM warm-up on every
invocation.
You point it at files or directories; it classifies each source by extension
(.java to Google Java Format, .kt / .kts to ktfmt) and formats
accordingly. Everything after the -- separator is passed through to the
formatters.
Fix files in place
Take a messily written Kotlin file:
// Greeter.kt
package sample
object Greeter {
fun greet(name: String): String
{
return "Hello, ${name}!"
}
} elide fmt -- Greeter.ktFormatted 1 Kotlin sources// Greeter.kt
package sample
object Greeter {
fun greet(name: String): String {
return "Hello, ${name}!"
}
}Kotlin is rewritten in place by default. Java is different in one important
way: Java files are only written back when you pass -i (or --replace) --
without it, the Java engine runs but leaves the file untouched:
// Message.java
public class Message {
public static String greet(String name){
return "Hello, "+name+"!";}
} elide fmt -- -i Message.java// Message.java
public class Message {
public static String greet(String name) {
return "Hello, " + name + "!";
}
}A mixed project is a single command -- -i applies to the Java files, and
Kotlin is rewritten in place regardless:
elide fmt -- -i srcFormatted 1 Java sources
Formatted 1 Kotlin sourcesCheck formatting in CI (without changing files)
The pair every CI pipeline wants is --dry-run (report, don't write) and
--set-exit-if-changed (exit non-zero if anything is out of format). Both flags
apply to Java and Kotlin at once:
elide fmt -- --dry-run --set-exit -if -changed src$ elide fmt -- --dry-run --set-exit-if-changed src
src/Message.java
Format-checking failed after 1 Java sources
Format-checked 1 Kotlin sources
$ echo $?
1An exit code of 1 fails the build; a clean tree exits 0. That single line
replaces a Java formatter check and a Kotlin formatter check with one call.
Zero-config, whole-project formatting
If you run the formatter with no file arguments, it reads the sources
globs from your elide.pkl project manifest and formats exactly the
files your project already declares:
# Format-check everything the project declares as source:
elide fmt -- --dry-run --set-exit -if -changedThere is no separate formatter config file to maintain -- style is controlled by flags, and the file set comes from the project you already defined.
Choose a style
Both formatters support their standard style options:
# Java: AOSP style (4-space indent) instead of the Google default
elide fmt -- --aosp -i Message.java
# Kotlin: Google internal style (2 spaces) or Kotlin-lang style (4 spaces)
elide fmt -- --google-style Greeter.kt
elide fmt -- --kotlinlang-style Greeter.ktSurgical edits
The Java engine can tidy imports without touching anything else, or format only a line range -- useful for large files and pre-commit hooks:
# Sort imports and drop unused ones, nothing else:
elide fmt -- --fix-imports-only -i Message.java
# Format only lines 10 through 25:
elide fmt -- --lines 10:25 -i Message.javaFlag reference
| Flag | Applies to | Effect |
|---|---|---|
-i, -r, —replace | Java | Write result back to the file (Java files are not modified without it). |
—dry-run, -n | Java + Kotlin | Report files that would change; do not write. |
—set-exit-if-changed | Java + Kotlin | Exit 1 if any file is not already formatted. |
—aosp | Java | Use AOSP style (4-space indent). |
—fix-imports-only | Java | Only sort/remove imports. |
—skip-removing-unused-imports | Java | Keep unused imports. |
—lines, —offset, —length | Java | Restrict formatting to a range. |
—meta-style / —google-style / —kotlinlang-style | Kotlin | Select Kotlin style (Meta is the default). |
—do-not-remove-unused-imports | Kotlin | Keep unused imports. |
If you only need one language, the engines are also exposed directly as elide javaformat -- ... and elide ktfmt -- .... See Format Java and Kotlin Formatting.
Call JavaScript from Python
Elide runs every language on one engine, so values cross language boundaries
without serialization. From Python, the built-in elide module lets you
evaluate JavaScript and export Python functions into the shared polyglot
bindings:
# interop.py
from elide import bind, js, poly
# Python -> JS: evaluate JavaScript and use the result back in Python.
total = js("[1, 2, 3, 4].reduce((a, b) => a + b, 0)")
print(f"js sum = {total}")
# Python -> host: export functions for JavaScript / the host to call.
@bind
def add(a, b):
return a + b
@poly(name="multiply")
def mul(a, b):
return a * b
print("interop ok") elide interop.pyjs sum = 10
interop okjs(source) evaluates a JavaScript string and hands the result back as a native
Python value; bind and poly publish Python callables under a name that other
languages can look up. See Elide + Python for the full interop
surface.
Use SQLite with zero dependencies
A database driver is a classic "install three packages first" task. In Elide,
SQLite is a built-in module -- import it and go:
// db.ts
import { Database } from "elide:sqlite";
const db = new Database(); // in-memory
db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);");
db.exec("INSERT INTO users (name) VALUES ('Ada'), ('Alan');");
const row = db.query("SELECT name FROM users ORDER BY id LIMIT 1;").get() as {
name: string;
};
console.log(`first user: ${row.name}`); elide db.tsfirst user: AdaNo npm install, no native build, no lockfile -- the driver ships inside the
runtime.
One project, three ecosystems
Real projects are usually already polyglot. Elide's manifest,
elide.pkl, declares npm, PyPI, and Maven dependencies together,
and a single elide install resolves all three with in-process resolvers -- no
npm, pip, or mvn to install separately.
amends "elide:project.pkl"
name = "polyglot-app"
dependencies {
maven {
packages {
"org.slf4j:slf4j-api:2.0.17"
}
}
npm {
packages {
"pluralize@8.0.0"
}
}
pypi {
packages {
"six==1.17.0"
}
}
}$ elide install
NPM packages installed (412ms)
+ pluralize@8.0.0
Python dependencies resolved (3ms)
Python packages installed (1ms)
Project dependencies installed in 513ms
Resolved 13 Maven dependencies (106ms)
Dependencies installed in 157msEverything lands under .dev/dependencies/, with conventional layouts (a root
node_modules symlink, a site-packages directory, a project-local Maven
repository under .dev/dependencies/m2) so existing tools still work. Imports
resolve against those installed packages with no further setup:
// main.ts
import pluralize from "pluralize";
console.log(pluralize("dependency", 3, true));$ elide run main.ts
3 dependenciesBuild and test with the same binary:
elide build # compile the project
elide test # run testsSee Dependencies for the resolver internals and Elide Projects for the full manifest schema.
Serve and iterate
Elide has an HTTP server built in. Serve a directory of static files, or use the dev server for live-reload while you work:
elide serve ./public # static file server (port 3000 by default)
elide serve --host 0.0.0.0 --port 8080 ./dist
elide dev ./public # live-reload + file watchingServing static files on 127.0.0.1:3000Both commands render an interactive terminal dashboard by default; pass
--no-tui for plain log output in CI. The full flag list is in the
CLI Reference.