~/TechPurAI
~/tutorials/ai-projects-with-python/setting-up-a-real-python-ai-project
beginner·part 1 of 22·3 min read

Setting Up a Real Python AI Project

Updated Aug 16, 2026Python · AI

This series builds ten real, working AI-powered applications — a chatbot, a REST API, a summarizer, a translator, and more. Every one of them starts from the same real setup, covered once here rather than repeated in every part.

The real, shared project structure

text
ai-projects/
├── venv/
├── .env
├── .gitignore
├── requirements.txt
└── shared/
    └── ai_client.py

Every project in this series lives as its own real script or app inside this shared workspace, reusing the same shared/ai_client.py module — a genuine, practical reflection of how a real team building several AI features wouldn't reinvent API setup in each one.

Real, practical environment setup

bash
mkdir ai-projects && cd ai-projects
python -m venv venv
source venv/bin/activate   # on Windows: venv\Scripts\activate
pip install anthropic python-dotenv
pip freeze > requirements.txt

This is the exact real setup from the AI Fundamentals series' own first coding part — this series picks up directly from that foundation rather than re-explaining it, and extends it into ten real, distinct applications. If venv and pip themselves are still new territory, the real, dedicated walkthrough covers exactly what's happening in those four lines.

Secure, real API key handling

text
# .env (never committed)
ANTHROPIC_API_KEY=your-real-api-key-here
text
# .gitignore
.env
venv/
__pycache__/

This is the same real security discipline established in the AI Fundamentals series — a real, uncommitted .env file, never a hardcoded key in source. Every project in this series loads its key exactly this way, with zero exceptions.

A real, shared client module

python
# shared/ai_client.py
import os
from dotenv import load_dotenv
from anthropic import Anthropic

load_dotenv()

def get_client() -> Anthropic:
    api_key = os.environ.get("ANTHROPIC_API_KEY")
    if not api_key:
        raise RuntimeError(
            "ANTHROPIC_API_KEY is not set — check your .env file"
        )
    return Anthropic(api_key=api_key)

Every real project in this series imports get_client() rather than repeating the same setup code — a genuine, practical reflection of the AI Fundamentals series' own DRY-adjacent instinct, and the real, explicit error check catches a missing key immediately with a clear message, rather than failing later with a confusing authentication error deep inside an API call. Notice the real -> Anthropic return type hint on get_client() too — exactly the kind of real, bug-catching annotation worth using consistently across a project like this.

Why it matters

Raising a real, explicit RuntimeError here — rather than letting a missing key fail silently or produce a cryptic error from inside the anthropic library — is a genuinely small but real detail that saves real debugging time. The first thing anyone (including your future self) sees when this project is missing its .env file is a clear, direct message pointing at the actual problem.

The real, two businesses this series builds for

text
Bright Leaf Coffee: a real, small e-commerce coffee subscription
  business, already built throughout the Google Ads, Meta Ads,
  Content Marketing, and AI Fundamentals series
GreenDesk: a real, B2B project-management SaaS business, already
  built throughout the same series

Every real project in this series builds a genuine feature for one of these two actual businesses — not a disconnected toy example, but the same real running examples used consistently across this entire site, so a feature built here connects directly to the marketing, content, and support context those other series already established.

A real, shared testing helper

python
# shared/ai_client.py (continued)
def ask(prompt: str, system: str = "", model: str = "claude-sonnet-5") -> str:
    client = get_client()
    response = client.messages.create(
        model=model,
        max_tokens=1024,
        system=system,
        messages=[{"role": "user", "content": prompt}],
    )
    return response.content[0].text

This real, minimal ask() helper wraps the exact request pattern from the AI Fundamentals series — genuinely useful for quick, real testing during development of any project in this series, before a specific project's own more tailored code (error handling, streaming, memory) gets built on top of it.

Next: building a real AI chatbot with Python — the first complete, working project in this series.

VK

Vijay Kumar

Founder of TechPurAI — writing hands-on tutorials and honest tool breakdowns.

LinkedIn ↗
next →2. Build an AI Chatbot with Python