AI Setup

This lesson explains how to start a Python project with AI assistance while keeping control over environment setup, architecture, dependencies, and verification.

Baseline Setup

Before asking AI to generate code, create a clean local project shell with a virtual environment, dependency installer, and test tooling.

mkdir my_python_app
cd my_python_app
python -m venv .venv
. .venv/Scripts/activate
python -m pip install --upgrade pip
pip install pytest ruff

Prompt Strategy

Good AI prompts define application type, package layout, tooling, coding style, and the exact outputs you want.

  1. State the project type: CLI, API, worker, automation tool, or data pipeline.
  2. Require a folder structure and dependency list before code generation.
  3. Ask for tests and run commands together with implementation.
Create a Python FastAPI starter project.
Use src/ layout, pytest, Ruff, and pyproject.toml.
Return folder structure first, then minimal files, then run commands.

Project Scaffold

AI is best used to generate a first scaffold that you immediately verify.

my_python_app/
  pyproject.toml
  README.md
  src/
    my_python_app/
      __init__.py
      main.py
  tests/
    test_main.py

Verification Loop

Never trust AI output without local checks. Every generated slice should pass format, lint, import, and test steps.

python -m pip install -e .
ruff check .
pytest

Architecture Guardrails

  • Do not let AI mix business logic into route handlers or CLI entrypoints.
  • Keep configuration, domain logic, and infrastructure code in separate modules.
  • Require AI to explain why each dependency is needed.
  • Prefer deterministic, small prompts over vague "build my app" requests.

AI Setup Lab

  1. Create a new Python project shell with venv and pytest.
  2. Use AI to propose a folder structure for a small API or CLI.
  3. Generate one feature and one test with AI.
  4. Run Ruff and pytest, then repair anything that fails.