Back to Playbook

Vibe Coding with Python

Python developers can vibe code too! Here's how to build modern web apps and APIs with Python, AI coding assistants, and the best tools for shipping fast.

1Django vs FastAPI: Which Framework?

Python has two excellent web frameworks. Pick based on what you're building, not what's 'better.'

Django

Django

Python's batteries-included web framework. Comes with admin panel, ORM, authentication, and forms out of the box. Fast to prototype, scales to production.

"Like a Swiss Army knife for Python web apps. Everything you need is already attached."

(Full-Stack Framework)

Strengths

  • • Batteries included (admin, auth, ORM)
  • • Great for full-stack apps
  • • Mature ecosystem (20+ years)
  • • Excellent documentation
  • • Built-in security features
  • • Template engine included

Trade-offs

  • • Heavier, more opinionated
  • • Slower for API-only projects
  • • Async support is newer

Best for: Full-stack apps, admin panels, content sites, and projects where you want everything in the box.

FastAPI

FastAPI

Modern Python framework for building APIs. Automatic API docs, type hints, async support, and blazing fast performance. Great for AI assistants to work with.

"Like Django's younger, faster sibling. Focuses on APIs and does them really well."

(Modern API Framework)

Strengths

  • • Blazing fast (async/await native)
  • • Auto-generated API docs
  • • Type hints with Pydantic
  • • Modern Python features
  • • Perfect for APIs and microservices
  • • Minimal boilerplate

Trade-offs

  • • No built-in admin panel
  • • Younger ecosystem
  • • Need to choose ORM separately

Best for: APIs, microservices, ML model serving, and projects where speed matters.

Vibe Stack

For API-first apps: FastAPI is the vibe. It's fast, modern, and Claude Code loves working with it.

For full-stack apps: Django is still excellent. Built-in admin alone saves weeks of work.

2Recommended Python Stack

Framework: FastAPI or Django

Choose based on your project type (see above)

Installation: pip install fastapi uvicorn or pip install django

Database: PostgreSQL

PostgreSQL

A powerful, open-source relational database. Rock-solid, feature-rich, and the choice for serious production apps.

"Like the Toyota Camry of databases. Reliable, well-documented, handles anything you throw at it."

via Neon

Neon

Serverless PostgreSQL. A modern database that auto-scales, branches like Git, and has a generous free tier. Perfect for vibe coding.

"Like PostgreSQL that wakes up when you need it and sleeps when you don't. Pay for what you use."

Best database for Python, serverless-ready

Why PostgreSQL

  • • Django's ORM loves it
  • • SQLAlchemy works perfectly
  • • JSON support for flexible data
  • • Best Python driver (psycopg3)

Why Neon

  • • Scale-to-zero (free tier)
  • • Instant database branching
  • • Connection pooling built-in
  • • Works with Django & FastAPI

ORM options: Django ORM (if using Django), SQLAlchemy 2.0 (for FastAPI), or Tortoise ORM (async alternative)

Deployment: Hosting Platforms (Railway or Render)

Python-friendly platforms with easy setup

Railway

  • • Deploy from GitHub in 1 click
  • • Auto-detects Python apps
  • • $5 free credit monthly
  • • Great DX

Render

  • • Free tier for web services
  • • Auto-scaling
  • • Static site hosting too
  • • Background workers

Alternative: Fly.io (more control), Heroku (classic but pricey), or Cloud Run (if you know Docker)

Authentication

Multiple options depending on framework

Django: Built-in Auth System

Django has excellent built-in user management. Add django-allauth for social logins.

FastAPI: python-jose + passlib

JWT tokens with bcrypt hashing. Or use FastAPI-Users for a full auth system.

Both: Clerk or Auth0

Drop-in auth services if you want to skip the setup. They have Python SDKs.

3Vibe Coding with Python + AI

Claude Code works excellently with Python! Here's how to get the most out of it.

Type Hints Are Your Friend

Claude understands your code better with type hints. Use them everywhere, especially with FastAPI and Pydantic.

# Good - Claude knows exactly what you want

def get_user(user_id: int) -> User | None:

return db.query(User).filter(User.id == user_id).first()

Use Virtual Environments

Claude can help manage dependencies, but it needs to know your env. Always use venv or poetry.

python -m venv venv

source venv/bin/activate # Mac/Linux

venv\Scripts\activate # Windows

pip install -r requirements.txt

Ask for Modern Python

Tell Claude you want Python 3.10+ features. You'll get match/case statements, better type hints, and async/await patterns. Example: "Use FastAPI with async SQLAlchemy 2.0 and Python 3.11 features."

Project Structure Matters

Claude works best with organized projects. Use a standard structure:

my-app/

├── app/

│ ├── main.py # FastAPI app or Django settings

│ ├── models.py # Database models

│ ├── routes/ # API endpoints

│ └── services/ # Business logic

├── tests/

├── requirements.txt

└── README.md

4Common Python App Patterns

Pattern 1: API-First with FastAPI + Next.js Frontend

Build your API in FastAPI (hosted on Railway), frontend in Next.js (hosted on Vercel). Best of both worlds.

FastAPI backendNext.js frontendNeon database

Pattern 2: Full-Stack Django + HTMX

Use Django templates with HTMX for dynamic UIs. No separate frontend framework needed. Ship fast!

Django + templatesHTMX for reactivityAlpine.js for JS

Pattern 3: ML Model API with FastAPI

FastAPI is perfect for serving ML models. Async support handles multiple requests efficiently.

FastAPIScikit-learn/PyTorchAuto-generated docs

Pattern 4: Django REST Framework for Mobile Apps

Use Django + DRF for robust APIs consumed by React Native or Flutter apps. Token auth built-in.

Django + DRFJWT authMobile clients

5Quick Start: FastAPI + Neon + Railway

1

Create FastAPI Project

mkdir my-api && cd my-api

python -m venv venv && source venv/bin/activate

pip install fastapi uvicorn sqlalchemy psycopg2-binary

2

Create Neon Database

Go to neon.tech, create a free database. Copy the connection string.

3

Write Your First Endpoint

Create main.py:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")

def read_root():

return {"message":"Hello World"}

4

Test Locally

uvicorn main:app --reload

Visit http://localhost:8000/docs for auto-generated API docs!

5

Deploy to Railway

Push to GitHub, connect Railway, deploy. Add DATABASE_URL env var. Done!

Your API is live! FastAPI automatically generates interactive docs at /docs. Share that with your frontend team.

Ready to vibe code with Python?

Python + AI assistants = shipping quality code fast.