A comprehensive, progressive learning journey through Pydantic data validation and modern Python application development. Three versions designed to take you from beginner to enterprise-level expertise.
π οΈ Fresh Installation? New to development or setting up from scratch? Check our Developer Setup Guide for complete installation instructions from a fresh OS.
# Clone the repository
git clone https://github.com/merca/python_basics_pydantic.git
cd python_basics_pydantic
# View all available learning versions
python run_version.py --info
# Check if dependencies are available for a version
python run_version.py --check basic
# Launch any version with automatic setup
python run_version.py basic # Start with fundamentals
python run_version.py intermediate # Database integration
python run_version.py advanced # Enterprise patternsHelper Script Features:
- π Dependency Checking: Validates required packages are available
- π Auto-Launch: Creates virtual environment and installs dependencies automatically
- π Version Info: Shows detailed comparison of all learning versions
- π― Smart Navigation: Handles platform differences (Windows/macOS/Linux)
New to Pydantic? π° Start Here!
# 1. Clone the repository
git clone https://github.com/merca/python_basics_pydantic.git
cd python_basics_pydantic
# 2. Start with BASIC version
cd basic
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
streamlit run app.pyAlready know Pydantic basics? π Jump to Intermediate!
# Skip to database integration
cd intermediate
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
streamlit run app.pyReady for enterprise patterns? π Go Advanced!
# Dive into production architecture
cd advanced
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
streamlit run main.pyClick to expand traditional pip/venv instructions
Basic Version:
cd basic
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
streamlit run app.pyIntermediate Version:
cd intermediate
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
streamlit run app.pyAdvanced Version:
cd advanced
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
streamlit run main.pyOur three-tier approach ensures you build a solid foundation before tackling complex concepts:
π° Basic π Intermediate π Advanced
Single File β Modular Structure β Layered Architecture
In-Memory Data β SQLite Database β Production Patterns
Direct Integration β Session Management β Dependency Injection
By completing all three versions, you'll have expertise in:
- π° Fundamentals - Core Pydantic validation, type safety, and error handling
- π Data Persistence - Database integration, ORM patterns, and session management
- ποΈ Architecture Patterns - Service layers, repositories, and dependency injection
- π‘οΈ Production Readiness - Error handling, testing, and performance optimization
- π― Best Practices - Code organization, documentation, and maintainability
Each version builds naturally on the previous one. No overwhelming jumps in complexity.
Not just toy examples - each version represents how you'd actually structure applications of that scale.
Every version is a fully functional employee management system you can run and explore.
Learn not just how to use Pydantic, but when and why to apply different patterns.
Extensive comments, learning notes, and architectural explanations built right into the code.
π° BASIC Version - Pydantic Fundamentals
- Python developers new to Pydantic
- Learning core validation concepts
- Understanding type safety benefits
- Single file (
app.py) - 620 lines - In-memory data storage (session state)
- Direct Streamlit integration
# Field validation and constraints
class Employee(BaseModel):
name: str = Field(min_length=2, max_length=50)
email: EmailStr
salary: Decimal = Field(ge=0, decimal_places=2)
# Custom validation logic
@field_validator('birth_date')
def validate_age(cls, v):
if calculate_age(v) < 16:
raise ValueError('Too young')
return v
# JSON serialization
employee = Employee(**data)
json_data = employee.model_dump(mode='json')- Interactive employee management form
- Real-time validation feedback
- JSON import/export functionality
- Basic analytics dashboard
π INTERMEDIATE Version - Database Integration
- Developers ready for persistence
- Learning SQLAlchemy + Pydantic patterns
- Understanding model inheritance
- Modular structure (5 files) - 1,200 lines
- SQLite database with SQLAlchemy ORM
- Proper separation of concerns
# Model inheritance hierarchy
class BaseEmployee(BaseModel):
# Shared fields and validation
class EmployeeCreate(BaseEmployee):
# Fields specific to creation
class Employee(BaseEmployee):
# Full model with database fields
id: Optional[int] = None
created_at: Optional[datetime] = None
# Database session management
@contextmanager
def session_scope():
session = SessionLocal()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()- Database-backed employee system
- Model inheritance patterns
- CRUD operations with validation
- Basic analytics with charts
π ADVANCED Version - Enterprise Patterns
- Senior developers planning production apps
- Learning enterprise architecture patterns
- Understanding complex system design
- Layered architecture (15+ files) - 3,000+ lines
- Service layer + Repository pattern
- Dependency injection and error handling
# Service layer for business logic
class EmployeeService:
def __init__(self, repository: EmployeeRepository):
self.repository = repository
def create_employee(self, data: EmployeeCreate) -> Employee:
# Business validation and coordination
# Repository for data access
class EmployeeRepository:
def create(self, employee: EmployeeCreate) -> Employee:
# Database operations abstraction
# Dependency injection
def get_employee_service() -> EmployeeService:
repository = get_employee_repository()
return EmployeeService(repository)- Production-ready architecture
- Comprehensive error handling
- Performance-optimized database operations
- Advanced testing patterns
- Python 3.8+ (Python 3.11+ recommended)
- Git for cloning the repository
- Virtual environment support (venv/conda)
# Check Python version
python --version # Should be 3.8+
# Clone repository
git clone https://github.com/merca/python_basics_pydantic.git
cd python_basics_pydantic
# Each version has independent setup
cd basic # or intermediate, or advanced
python -m venv venv- VS Code with Python extension
- PyCharm (Community/Professional)
- Cursor for AI-assisted development
Week 1: π° Basic Version
βββ Day 1-2: Setup and basic validation
βββ Day 3-4: Custom validators and JSON operations
βββ Day 5: Exercises and experimentation
Week 2: π Intermediate Version
βββ Day 1-2: Database integration
βββ Day 3-4: Model inheritance and CRUD
βββ Day 5: Analytics and architecture study
Week 3-4: π Advanced Version
βββ Week 3: Service layer and repository patterns
βββ Week 4: Testing, optimization, and production concepts
βββ Final project: Extend with your own features
After each version, you should be able to:
π° Basic Completion:
- Explain Pydantic's value proposition
- Create models with field validation
- Handle validation errors gracefully
- Serialize/deserialize JSON data
π Intermediate Completion:
- Design model inheritance hierarchies
- Integrate Pydantic with SQLAlchemy
- Manage database sessions properly
- Implement CRUD operations with validation
π Advanced Completion:
- Design service layer architectures
- Implement repository patterns
- Apply dependency injection principles
- Plan production deployment strategies
python_basics_pydantic/
βββ π° basic/ # Single-file fundamentals (620 lines)
β βββ app.py # Main application
β βββ requirements.txt # 3 core dependencies
β βββ README.md # Beginner guide
βββ π intermediate/ # Database integration (1,200 lines)
β βββ models/ # Pydantic models
β βββ database/ # SQLAlchemy integration
β βββ utils/ # Helper functions
β βββ app.py # Multi-page application
β βββ requirements.txt # 6 dependencies
β βββ README.md # Intermediate guide
βββ π advanced/ # Enterprise patterns (3,000+ lines)
β βββ app/ # Application layer
β β βββ components/ # Reusable UI components
β β βββ pages/ # Page modules
β β βββ services/ # Business logic layer
β βββ src/ # Core business layer
β β βββ models/ # Advanced Pydantic models
β β βββ database/ # Repository pattern
β βββ data/ # Database files
β βββ main.py # Application entry point
β βββ requirements.txt # 20+ production dependencies
β βββ README.md # Enterprise guide
βββ π run_version.py # Helper script for easy switching
βββ π README.md # Main learning path documentation
βββ π οΈ DEVELOPER_SETUP.md # Complete setup guide (fresh OS)
βββ π LICENSE # MIT license
βββ βοΈ pyproject.toml # Project configuration
βββ π· .gitignore # Git exclusions
The run_version.py script provides a convenient way to manage all learning versions:
# Show version information and features
python run_version.py --info
# Check if system has required dependencies
python run_version.py --check [basic|intermediate|advanced]
# Launch a version (creates venv, installs deps, starts app)
python run_version.py [basic|intermediate|advanced]
# Get help and see all options
python run_version.py --help# Start learning journey
python run_version.py --info # See what's available
python run_version.py --check basic # Verify system readiness
python run_version.py basic # Launch basic version
# Progress to intermediate
python run_version.py --check intermediate
python run_version.py intermediate
# Master advanced patterns
python run_version.py --check advanced
python run_version.py advancedπ° Basic Version: π ~620 lines, π¦ 3 packages, β±οΈ 30-60min
π Intermediate: π ~1,200 lines, π¦ 6 packages, β±οΈ 1-2hrs
π Advanced: π ~3,000 lines, π¦ 20+ packages, β±οΈ 4-8hrs
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Total Learning: π ~5,000 lines, π Beginner β Expert
- π Documentation: Each version has comprehensive README.md files
- π οΈ Setup Issues: Check DEVELOPER_SETUP.md for installation help
- π Helper Script: Use
python run_version.py --helpfor quick assistance - π Code Comments: Extensive educational comments explain every concept
- π§ͺ Experimentation: Break things to understand how they work
- π GitHub Issues: Report bugs, ask questions, or request features
We welcome contributions! Ways to help:
- Improve Documentation: Fix typos, add examples
- Enhance Examples: Add new features or use cases
- Share Feedback: Tell us about your learning experience
- Create Extensions: Build on top of the advanced version
"This progressive approach helped me understand not just HOW to use Pydantic, but WHEN and WHY to apply different patterns. The advanced version gave me confidence to architect production applications."
β Senior Python Developer
"Starting with the basic version made Pydantic approachable. By the time I reached the advanced patterns, I understood the reasoning behind each architectural decision."
β Full Stack Engineer
- Personal Projects: Use these patterns in your own applications
- Work Projects: Introduce Pydantic to your team's codebase
- Open Source: Contribute to Pydantic or related projects
- FastAPI: Web APIs with automatic validation
- SQLModel: Type-safe database models
- Pydantic v3: Stay current with latest features
- Blog Posts: Write about your learning journey
- Conference Talks: Share architectural insights
- Mentoring: Help others learn Pydantic
This project is licensed under the MIT License - see the LICENSE file for details.
- Pydantic Team for creating an amazing validation library
- Streamlit Team for the excellent web app framework
- SQLAlchemy Team for powerful ORM capabilities
- Python Community for continuous innovation
π― Ready to start your Pydantic journey?
π° Begin with Basic Version β
Transform from Pydantic newcomer to enterprise architect
Happy Learning! π