A complete, beginner-friendly curriculum taking you from modern Mojo (v1.2+) fundamentals to building a production-grade backend combining FastAPI, SQLx-style SQLite persistence, and Better Auth-compatible authentication.
Managed with Astral's uv package manager for instant, reproducible setup.
If you learned Mojo during its early Alpha releases, modern Mojo has matured into a stable systems language with key syntax unifications:
| Feature | Alpha Era (Old) | Modern Mojo (v1.2+) | Why It Changed |
|---|---|---|---|
| Package Management | modular CLI / conda |
uv / PyPI (uv add mojo) |
Standardized under Python's fastest package ecosystem |
| Functions | fn (strict) vs def (loose) |
Unified def |
Eliminated dual-keyword fragmentation; def has full systems safety |
| Variables | var (mut) vs let (immut) |
Unified var |
Simplified runtime variables; compile-time constants use comptime |
| Compile-Time | alias |
comptime |
Clearer meta-programming semantics (comptime X = 10, if comptime(...)) |
| Standard Library | from collections import List |
from std.collections import List |
Standardized under the std root namespace |
| Backend Architecture | Raw sockets inside Mojo | Compiled .so in FastAPI |
FastAPI handles async ASGI HTTP; Mojo handles SIMD/heavy compute |
- macOS (Apple Silicon) or Linux: Supported natively out of the box.
- Python: Python 3.15 (managed automatically via
uvor system Python 3.15). - Windows: Install and run via WSL2 (
wsl --install -d Ubuntu). - uv: If not installed, get it via
curl -LsSf https://astral.sh/uv/install.sh | shorbrew install uv.
Clone the repository and install all dependencies in one command:
git clone https://github.com/vinitchuri/Mojo-Tutorial.git
cd Mojo-Tutorial
uv syncVerify your Mojo compiler installation:
uv run mojo --version
# Output: Mojo 1.2.0 (2016d0cd)- Chapter 01: Hello, Mojo!
The modern entry point (
def main():), running scripts withuv run mojo, and compiling native binaries withmojo build. - Chapter 02: Variables & Compile-Time Constants
Runtime mutable variables (
var), type inference, and compile-time constants (comptime). - Chapter 03: Data Types & Tuples
Primitive scalar types (
Int,Float64,Bool,String) and heterogeneous tuples. - Chapter 04: Control Flow
Conditionals (
if/elif/else), loops over ranges, loop controls, and compile-time branching withif comptime(...).
- Chapter 05: Functions & Error Handling
Typed function signatures, default arguments, error propagation with
raises, and structuredtry ... exceptblocks. - Chapter 06: Ownership & Borrowing Conventions
Argument conventions (
read,mut,var,out), zero-cost borrowing, and the transfer operator (^) for moving buffers. - Chapter 07: Collections & Zero-Cost Structs
Homogeneous
List[T], Swiss-tableDict[Key, Value], and building valuestructmodels. - Chapter 08: Traits, Generics & SIMD Vectorization
Polymorphic interfaces (
trait), compile-time monomorphized generics, and hardware SIMD registers (SIMD[DType.float32, 4]).
- Chapter 09: Native Mojo Python Extensions
Calling Python from Mojo, and compiling Mojo into a native CPython shared library (
.so) usingPythonModuleBuilderand@export abi("C"). - Bonus Systems Lab: Raw TCP Socket HTTP Server An educational systems lab implementing TCP socket accept loops, HTTP byte framing, and JSON response formatting directly in Mojo.
- Chapter 10: SQLx-Style Persistence with SQLite
Raw parameterized
.sqlqueries, versioned sequential migrations, and a pre-flight SQL query verifier usingEXPLAINto catch schema mismatches before deployment. - Chapter 11: Better Auth-Compatible Authentication
Exact 4-table schema (
user,session,account,verification), Argon2id password hashing (argon2-cffi), and HMAC-SHA256 signedHttpOnly; SameSite=Laxsession cookies. - Chapter 12: Production FastAPI Capstone API
Connecting everything together into a production REST API: protected endpoints, dependency injection guards (
CurrentUser), and async dispatch of compute-heavy SIMD scoring to native compiled Mojo code.
You can execute every tutorial chapter in sequence:
uv run mojo chapters/01_hello/hello.mojo
uv run mojo chapters/02_variables_and_comptime/variables.mojo
uv run mojo chapters/03_datatypes/datatypes.mojo
uv run mojo chapters/04_control_flow/control_flow.mojo
uv run mojo chapters/05_functions_and_errors/functions.mojo
uv run mojo chapters/06_ownership_and_borrowing/ownership.mojo
uv run mojo chapters/07_collections_and_structs/structs.mojo
uv run mojo chapters/08_traits_generics_and_simd/simd_compute.mojo
uv run mojo chapters/09_mojo_python_extensions/interop_demo.mojouv run python chapters/09_mojo_python_extensions/run_extension.pyuv run python -m backend.app.db.migrator
uv run python -m backend.app.db.verifier
uv run pytest backend/tests/ -v# Format and lint with Ruff
uv run ruff format .
uv run ruff check .
# Fast static type checking with Pyrefly
uv run pyrefly checkContributions, feedback, and questions are welcome! Feel free to open an issue or submit a pull request. Licensed under the Apache 2.0 License.