Python in the AI Era
How Python powers AI work: the library map, calling models, tokens, streaming, structured output, RAG, agents, evals, ML basics, PyTorch and AI assistants.
Almost every AI product you use is Python on the inside: a thin layer of ordinary code around a model. A model is a program that has already learned from a huge amount of example data. This phase teaches the ordinary code around it from scratch, with the Python you already know. Every runnable example uses a fake model written in the example itself: a plain function that returns scripted text. We do this because a real model needs a paid account, a secret key and an internet connection, and none of those work inside this lesson page. The fake has the same shape as the real thing, so you see the real mechanics (messages, tokens, retries, tool calls, retrieval) with no API key and no cost. It does not show how smart a real model is.
Before you start. This phase leans on earlier topics. If you skipped ahead, go back for these first: functions (Topics 5.1 to 5.3), dictionaries (Topic 4.4) and nested data (Topic 4.8), JSON (Topic 7.7), dataclasses (Topic 8.8), generators (Topic 9.2), type hints (Topic 10.1), pytest and fakes (Topics 11.2 and 11.4), async and await (Topics 12.6 to 12.8), NumPy arrays and vectors (Topics 14.1 and 14.5), HTTP clients and retries (Topics 15.1 and 15.2) and Pydantic (Topic 15.4). Each topic below repeats the key idea in one line when it needs it, but those lines are reminders, not lessons.
You will meet the whole stack as a map, then build the pieces by hand: a client, a token budget, a stream, a validator, a prompt template, a vector search, a RAG pipeline, an agent loop and an eval. Real SDK code is shown in separate blocks you can copy later when you have a key. Doing it by hand first is what lets you debug any framework.
This is an honest introduction, not the whole subject. Each topic ends by naming the Hectal course that will go deeper: LLM engineering, RAG and agents, machine learning and deep learning are each planned as a full course. Security content here is defensive only: what prompt injection is, why retrieved and tool text is untrusted, and how to reduce the risk.
Practise this phase
Hands-on exercises: write the code, run it, and press Check to have it tested automatically.