# Language Constraints for Python, TypeScript, Rust, and Julia Code Implementations

> Discover language constraints for Python, TypeScript, Rust, and Julia in AI engineering. Learn how specific standard libraries and whitelisted packages ensure clarity and reproducibility.

- Repository: [Rohit Ghumare/ai-engineering-from-scratch](https://github.com/rohitg00/ai-engineering-from-scratch)
- Tags: deep-dive
- Published: 2026-07-30

---

**The ai-engineering-from-scratch curriculum enforces strict language constraints defined in [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) that limit each language to specific standard libraries and whitelisted packages to ensure educational clarity and reproducibility.**

The **ai-engineering-from-scratch** repository by Rohit Ghumare maintains rigorous **language constraints** for Python, TypeScript, Rust, and Julia implementations to prevent hidden dependencies and keep the focus on algorithmic fundamentals. These rules are codified in the repository's [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) file and apply to every lesson in the `code/` directory, ensuring that learners see explicit implementations rather than black-box library calls.

## Dependency Allowlist by Language

The constraints operate on an explicit allowlist model documented in the **Dependencies** table within [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md). Each language has specific permitted modules that balance educational utility with the "stdlib-first" pedagogical approach.

### Python: Standard Library Plus Scientific Stack

Python implementations may use the standard library plus five explicitly whitelisted packages: **`numpy`**, **`torch`**, **`h5py`**, **`zstandard`**, and **`safetensors`**.

```python
import numpy as np          # ✅ permitted

import torch               # ✅ permitted

# from pandas import DataFrame   # ❌ not on the allowlist

def relu(x):
    return np.maximum(0, x)   # simple, self‑contained implementation

```

This limited set ensures that machine learning primitives are available while preventing lessons from relying on high-level framework abstractions that obscure the underlying mathematics.

### TypeScript: Node.js 20+ with Minimal Web Framework

TypeScript code must target **Node.js 20+** and restricts dependencies to the standard library plus four specific npm packages: **`hono`**, **`zod`**, **`ws`** (WebSockets only), and **`@hono/node-server`**.

```typescript
import { Hono } from 'hono';          # ✅ permitted

import { z } from 'zod';              # ✅ permitted

// import express from 'express';    # ❌ not allowed

const app = new Hono();
app.get('/', c => c.text('Hello, world!'));

```

This constraint ensures server-side implementations remain lightweight and avoid the complexity of larger Node.js frameworks.

### Rust: Stdlib-Only Compilation

Rust implementations are **stdlib-only**, compiled with `rustc --edition 2021`. No external crates from crates.io are permitted.

```rust
// No external crates – everything comes from the Rust stdlib
fn sigmoid(x: f64) -> f64 {
    1.0 / (1.0 + (-x).exp())
}

fn main() {
    println!("{}", sigmoid(0.5));
}

```

Learners must implement utility functions—such as mathematical operations or data structures—from scratch using only `std`, reinforcing low-level systems understanding.

### Julia: Core Standard Library Modules

Julia implementations are restricted to four standard library modules: **`Random`**, **`Statistics`**, **`LinearAlgebra`**, and **`Printf`**. External packages like Flux or DataFrames are explicitly prohibited.

```julia
using Random   # ✅ allowed

using Statistics  # ✅ allowed

# using Flux   # ❌ not permitted

function normalize(v::Vector{Float64})
    μ = mean(v)
    σ = std(v)
    return (v .- μ) ./ σ
end

```

This forces explicit algorithmic implementation rather than relying on Julia's rich package ecosystem.

## Educational and Architectural Rationale

The strict **language constraints** serve three primary purposes defined in the curriculum architecture:

- **Educational Clarity** – By limiting dependencies to the language runtime or minimal scientific stacks, learners trace the full derivation of algorithms rather than making black-box library calls.
- **Reproducibility** – The deterministic import set enables the CI pipeline to execute every lesson without hidden network fetches or version drift.
- **Uniform Lesson Contract** – Each lesson's [`docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/docs/en.md) must list implemented languages in the `**Languages:**` front-matter field, which must align with the `main.*` files present in the lesson's `code/` folder.

## Compliance Validation and Enforcement

The repository enforces these constraints through an **audit script** referenced in [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md). This script validates that:

- All `main.*` files in lesson `code/` directories use only allowed imports.
- The `**Languages:**` metadata in lesson documentation matches the actual source files present.
- No unauthorized external dependencies appear in import statements.

When a lesson requires functionality outside the allowlist, maintainers must either implement the feature from scratch or document explicitly why the dependency is disallowed, citing the stdlib-first pedagogical rationale.

## Summary

- **Python** allows the standard library plus `numpy`, `torch`, `h5py`, `zstandard`, and `safetensors`.
- **TypeScript** restricts dependencies to Node.js 20+ stdlib plus `hono`, `zod`, `ws`, and `@hono/node-server`.
- **Rust** permits only the standard library (`rustc --edition 2021`) with zero external crates.
- **Julia** limits usage to `Random`, `Statistics`, `LinearAlgebra`, and `Printf` from the standard library.
- All constraints are defined in [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) and enforced by an audit script that maintains the **Languages:** contract between documentation and source files.

## Frequently Asked Questions

### What happens if I need a package not on the allowlist?

You must either implement the required functionality from scratch using permitted libraries (for example, writing manual matrix multiplication instead of using a banned crate) or explicitly document why the dependency violates the stdlib-first pedagogical approach. The [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) file outlines this escalation path for edge cases.

### How are the language constraints enforced in the repository?

An automated audit script referenced in [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) scans lesson directories to verify that `main.*` files contain only allowed imports. It also cross-references the `**Languages:**` front-matter field in [`docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/docs/en.md) against the actual source files present in the `code/` folder to ensure documentation accuracy.

### Why does Rust have stricter constraints than Python?

The **ai-engineering-from-scratch** curriculum applies a "stdlib-first" philosophy most strictly to Rust because its standard library provides sufficient systems programming primitives for educational algorithms. Python receives a broader allowlist (including `numpy` and `torch`) to accommodate tensor operations essential to AI engineering while still avoiding high-level framework abstractions.

### Can I use third-party crates in Rust if they're small and focused?

No. The [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) explicitly mandates **stdlib-only** for Rust with `rustc --edition 2021`. Even small utility crates are prohibited to ensure learners understand the underlying implementations and to maintain deterministic builds without network dependencies during compilation.