Tools Setup

Python and a Virtual Environment

Example

Use Python 3.10 or newer. Create a project folder with its own virtual environment:

mkdir shopease-ai && cd shopease-ai
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install anthropic python-dotenv
python --version

Example output

Successfully installed anthropic-1.x python-dotenv-1.x ...
Python 3.12.4

API Keys and .env

An API key is a secret password for the model provider. Create one in the provider console (for Claude: console.anthropic.com). Never paste it into code or commit it to Git. Put it in a .env file and add .env to .gitignore:

# .env  (never commit this file)
ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxx
.venv/
.env
__pycache__/

How a .env File Is Read

Example

python-dotenv reads the file and puts each line into os.environ. Here is the same idea in a few lines of plain Python (using a temporary file that is deleted at the end):

import os, tempfile

path = os.path.join(tempfile.gettempdir(), "genai_basic_demo.env")
with open(path, "w") as f:
    f.write("# secrets\nANTHROPIC_API_KEY=sk-ant-api03-demo1234567890\nAPP_ENV=dev\n")

def load_env(path):
    with open(path) as f:
        for line in f:
            line = line.strip()
            if line and not line.startswith("#"):
                key, _, value = line.partition("=")
                os.environ.setdefault(key, value)

load_env(path)
os.remove(path)

key = os.environ.get("ANTHROPIC_API_KEY", "")
print("APP_ENV:", os.environ["APP_ENV"])
print("key loaded:", bool(key), "| masked:", key[:10] + "..." + key[-4:])

Output

APP_ENV: dev
key loaded: True | masked: sk-ant-api...7890

Tip: When you log or print a key to check it, print only a masked version like above. Leaked keys get abused within minutes; if one leaks, revoke it in the console immediately.

Editor: VS Code or Jupyter

  • VS Code with the Python extension: best for apps (FastAPI backends, scripts). Select the .venv interpreter.
  • Jupyter notebooks (pip install jupyter, or VS Code notebooks, or Google Colab): best for experimenting with prompts and seeing outputs cell by cell.
  • Both read environment variables the same way; in a notebook call load_dotenv() in the first cell.