Docs Examples Why Mantra About Language Tour Download GitHub
v0.2.0 — mantra.web ยท mantra.rest ยท mantra.sql.orm Enhanced

Clarity
at scale.

Mantra is a fast, expressive programming language built in Rust & C++. Full object-oriented design โ€” classes, interfaces, inheritance, abstract classes & static members โ€” with Python-like readability.

hello.mantra
def greet(name: String) -> String: return "Hello, " + name + "! Welcome to Mantra." class Counter: def __init__(self, start: Int): self.value = start pub def tick(self): self.value = self.value + 1 def main() -> Int: let msg = greet("Developer") print(msg) mut c = Counter(0) c.tick() c.tick() print("Count: " + str(c.value)) # Count: 2 return 0

Built for serious software.

Every feature in Mantra exists to help you write clear, structured, maintainable code — at any scale.

Read Full Architecture & Rust vs. C++ Analysis →
๐Ÿ›๏ธ
Full OOP
Classes with constructors, public & private members, __init__, and self. Build real data models fast.
๐Ÿ”—
Interfaces
Define contracts with interface. Any class can implements multiple interfaces enabling true polymorphism.
๐Ÿงฌ
Inheritance
extends parent classes, call super().__init__(), and override methods. Full multi-level class hierarchies.
๐Ÿ”’
Abstract Classes
Define abstract blueprints with abstract class and abstract def. Force subclasses to implement required behaviour.
โšก
Static Members
Class-level constants and functions with static. Utility classes like MathUtils.square(7) with zero boilerplate.
๐Ÿงฉ
Properties & Composition
Computed @property getters and object composition โ€” build rich models by assembling simpler objects.
๐Ÿฆ€
Rust + C++ Core
Built on a 8-crate Rust workspace (mantrac_lexer, mantrac_parser, mantrac_vm, mantrac_codegenโ€ฆ). Native code output via Clang.
๐Ÿ“ฆ
Rich Standard Library
Built-in packages: mantra.lang, mantra.io, mantra.util.collections, mantra.net.http, mantra.sql.orm.
๐Ÿ› ๏ธ
Mantra MDK
The Mantra Development Kit scaffolds projects, formats code, generates docs, and manages mantra.toml manifests.
๐Ÿค–
AI & LLM Friendly
Mantra's consistent, minimal syntax is ideal for AI code generation and LLM integration. One class model, one function signature, no ambiguous overloads โ€” AI assistants produce correct Mantra code on first attempt. The clean AST also makes Mantra a natural target for program synthesis tools.
๐Ÿฆ€
Rust + C++ Performance
The entire toolchain โ€” lexer, parser, type checker, VM, and code generator โ€” is written in Rust. Zero garbage collection pauses, memory-safe by default, and production-grade error diagnostics. The native emit path leverages Clang/LLVM for world-class optimisation with no runtime overhead.
๐ŸŒ
Build & Contribute
Use Mantra's built-in standard packages โ€” mantra.io, mantra.net.http, mantra.sql.orm โ€” as a foundation to build libraries and share them with the community. The MDK provides mantra new, mantra doc, and mantra fmt so contributing is one command away.

Batteries included.

Mantra ships with a curated set of packages covering I/O, collections, networking, and database access — no third-party setup required.

mantra.lang

Core language foundation, primitive wrappers, and base exceptions.

ObjectStringListBaseExceptionEquatable
View Package →

mantra.io

Console output, file read/write, and environment variable access.

ConsoleFileEnvironment
View Package →

mantra.util.collections

Classic data structures: hash maps, stacks, and queues.

HashMapStackQueue
View Package →

mantra.net.http

HTTP request/response models and server routing primitives.

HttpRequestHttpResponseHttpServer
View Package →

mantra.sql.orm

Pluggable database adapters: swap MySQL and PostgreSQL without changing your service code.

DatabaseAdapterModelMySQLAdapterPostgreSQLAdapter
View Package →

mantra.mdk

Developer tooling: project scaffolding, doc generation, and formatting.

ProjectScaffolderDocGeneratorFormatterPackageManifest
View Package →

mantra.web NEW v0.2.0

HTTP server, URL router, request/response models, middleware pipeline, and template engine.

ServerRouterRequestResponseMiddlewareTemplate
View Package →

mantra.rest NEW v0.2.0

REST controller base, JSON serializer, typed route handlers, and standardised API response envelope.

RestControllerJsonSerializerRouteHandlerApiResponsePagination
View Package →

mantra.sql.orm Enhanced v0.2.0

Now includes QueryBuilder (fluent SQL), SQLiteAdapter (embedded / :memory:), and Migration + SchemaBuilder.

QueryBuilderSQLiteAdapterMigrationSchemaBuilderModel
View Package →

See Mantra in action.

Explore the language feature by feature โ€” every snippet is runnable with mantrac.

01_basics.mantra

From high-level code to native binary.

Every .mantra file passes through a deterministic 6-stage pipeline built entirely in Rust. The same clean source code can either run instantly on the Mantra VM or be compiled to a fully optimised native binary via Clang — your choice at the command line.

SOURCE .mantra High-level source Python-like syntax UTF-8 LEXER mantrac_lexer Tokenises source โ†’ Token Stream Tokens PARSER mantrac_parser Recursive descent โ†’ AST Nodes AST TYPE CHECKER mantrac_checker Name resolution Type verification --emit vm --emit native VM PATH mantrac_vm Bytecode interpreter Zero compile wait Direct Output REPL / script fast iteration NATIVE PATH mantrac_codegen C99 emitter โ†’ Clang/LLVM Native Binary OS-optimised maximum perf Source Rust Crates VM Output Native Output
1

Source Code (.mantra)

Developers write expressive, Python-like Mantra source code โ€” classes, interfaces, functions. The file is read as UTF-8 text and passed to the lexer.

2

Lexer โ€” mantrac_lexer

The Rust lexer scans the raw characters and produces a flat Token Stream (keywords, identifiers, literals, operators). No allocation-heavy trees yet.

3

Parser โ€” mantrac_parser

A zero-copy recursive-descent parser turns the token stream into a typed Abstract Syntax Tree (AST) using nodes defined in mantrac_ast.

4

Type Checker โ€” mantrac_checker

Name resolution, interface contract verification, and override correctness are enforced. Errors are reported with precise source locations before any code runs.

5a

VM โ€” mantrac_vm --emit vm

The verified AST is walked by the Rust bytecode interpreter. Zero compile delay โ€” perfect for scripting, REPL sessions, and rapid iteration during development.

5b

Codegen โ€” mantrac_codegen --emit native

Emits portable C99 from the AST, then invokes Clang/LLVM to produce a fully optimised, OS-native binary. Maximum performance for production workloads.

High-level language. Low-level speed.

Mantra bridges the gap between developer productivity and machine performance. Write expressive, readable code once โ€” execute it two ways.

โšก
VM Path — mantrac_vm
Instant. No compile wait.

The Mantra VM is a tree-walking bytecode interpreter written in Rust. Your source is parsed, type-checked, then executed directly โ€” no intermediate binary. Ideal for scripting, test suites, CI pipelines, and interactive REPL sessions.

terminal
$ mantrac hello.mantra # Runs immediately via VM โ€” no binary produced Hello, Developer! Welcome to Mantra.
๐Ÿš€
Native Path — mantrac_codegen
Maximum performance. OS-native binary.

The code generator emits portable C99 from your verified AST, then hands it to Clang/LLVM for full optimisation. The result is a platform-native binary โ€” no runtime, no GC, no VM overhead. Used for production services, CLI tools, and performance-critical applications.

terminal
$ mantrac hello.mantra --emit native -o hello # Emits C99 โ†’ Clang โ†’ native binary โœ“ hello (macOS ARM64, 48KB, no runtime) $ ./hello Hello, Developer! Welcome to Mantra.
Compilation Pipeline Summary
.mantra source โ†’ Lexer โ†’ Parser + AST โ†’ Type Checker โ†’ VM (fast) / C99 โ†’ Clang โ†’ Binary

Build. Contribute. Grow.

Mantra is MIT-licensed and community-driven. Use the standard packages as building blocks, publish your own libraries, and help shape the language through GitHub contributions and RFCs.

๐Ÿ“ฆ

Use Standard Packages

Build on top of mantra.lang, mantra.io, mantra.net.http, and mantra.sql.orm. Complete docs with examples for every class and method.

Browse Packages →
๐Ÿ› ๏ธ

Scaffold & Ship

Create a new Mantra project, implement your library, and publish it. The MDK handles project layout, doc generation, and formatting automatically.

$ mantra new my_lib $ mantra doc $ mantra fmt
๐Ÿค

Contribute to Core

The 8-crate Rust workspace is structured for contribution. Add stdlib classes, fix bugs in the checker, improve the VM, or write new codegen backends.

View on GitHub →
๐Ÿค–

AI-Powered Development

Mantra's unambiguous syntax makes it the ideal language for AI-assisted coding. LLMs produce correct Mantra code with high reliability โ€” fewer corrections, faster shipping.

See Examples →
Rust + C++
Compiler Backend
11 Crates
Modular Toolchain
8 Packages
Standard Library
MIT
Open Source

Up and running in 60 seconds.

Install the MDK, create a project, write your first .mantra file, and run it.

1. Install & verify

Download the installer for your platform from the Downloads page, then verify:

terminal
$ mantra --version Mantra Development Kit (MDK) v0.1.0-draft Compiler: mantrac 0.1.0-draft Host Target: aarch64-apple-darwin $ mantrac --help Mantra Compiler (mantrac) v0.1.0-draft Usage: mantrac <input.mantra> [options] --emit vm Run on the Mantra VM (default) --emit native Compile to native binary via Clang --check Type-check only, no output

2. Create a new project

Use the MDK scaffolder to generate a project skeleton:

terminal
$ mantra new my_app โœ“ Created project: my_app/ my_app/ โ”œโ”€โ”€ mantra.toml โ””โ”€โ”€ src/ โ””โ”€โ”€ main.mantra $ cat my_app/mantra.toml [package] name = "my_app" version = "0.1.0" edition = "2026" license = "MIT" [build] entry = "src/main.mantra"

3. Write & run

Edit src/main.mantra and run with mantrac:

src/main.mantra
class Greeter: def __init__(self, name: String): self.name = name pub def greet(self) -> String: return "Hello, " + self.name + "! Welcome to Mantra." def main() -> Int: greeter = Greeter("Developer") print(greeter.greet()) return 0
terminal
$ mantrac src/main.mantra Hello, Developer! Welcome to Mantra.