21  Appendix A — Environment Setup

This appendix gets the book’s code running on your machine.

21.1 Prerequisites

  • Python 3.11+
  • Quarto CLI (to build the book)
  • An OpenAI API key (for chapters that call the API)

21.2 Create a virtual environment

python -m venv .venv
# Windows (PowerShell)
.venv\Scripts\Activate.ps1
# macOS / Linux
# source .venv/bin/activate

pip install -r requirements.txt

21.3 Configure secrets

Create a .env file in the repo root (it is git-ignored):

OPENAI_API_KEY=sk-...your key...

Load it in code with python-dotenv:

from dotenv import load_dotenv
import os
load_dotenv()
client_key = os.environ["OPENAI_API_KEY"]
WarningSafety

Never commit .env or paste keys into chapters. Rotate any key that leaks.

21.4 Build the book

quarto preview     # live-reload while writing
quarto render      # full HTML + PDF build into _output/

21.5 Package notes

Agent SDKs evolve quickly. If an import name in a chapter differs from the installed package, check the library’s current docs and update requirements.txt. Versions are pinned to keep examples reproducible.