Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of two database tables connected by a foreign key relationship line, representing SQLAlchemy primary and foreign key mappings.
Python

Python SQLAlchemy Primary Key, Foreign Key, and Relationships

python sqlalchemy primary key foreign key and relationships: Define primary keys, foreign keys, and relationship() mappings in SQLAlchemy, covering one-to-many, many-t...

SQLAlchemyORMDatabase RelationshipsForeign Keys
Diagram showing a Python SQLAlchemy declarative model mapping a table with columns and relationships.
Python

Python SQLAlchemy Declarative Models: Tables and Columns

Learn how to map Python classes to database tables with SQLAlchemy declarative models, including column types, constraints, indexes, and relationships.

SQLAlchemyDeclarative ModelsDatabase SchemaORM
Illustration of SQLAlchemy engine, connection, session, and sessionmaker as layered components in a database access stack
Python

SQLAlchemy Engine, Connection, Session, and Sessionmaker Explained

Understand the distinct roles of SQLAlchemy's Engine, Connection, Session, and Sessionmaker, including when to use each, common pitfalls, and a web application session pattern.

SQLAlchemyORMdatabasePython
Side-by-side comparison of Pydantic v1 and v2 API methods, with a migration arrow between them.
Python

python pydantic v1 vs v2: Key Differences and Migration

Compare python pydantic v1 vs v2: API changes, validation behavior, performance, and a practical migration path for existing projects.

PydanticData ValidationPython MigrationType Hints
A developer inspecting a Pydantic ValidationError with error details in a Python project
Python

Handling Python Pydantic Validation Errors

Learn how to catch, inspect, and customize Pydantic validation errors in Python, including error structure, manual raising, and FastAPI request handling.

pydanticvalidationerror handlingfastapi
A split diagram comparing Pydantic's BaseModel class and dataclass decorator, with validation arrows and code snippets
Python

Python Pydantic Dataclass vs BaseModel: Choosing the Right Approach

Compare Pydantic's dataclass and BaseModel for validation, serialization, and integration. Learn which approach fits your codebase and when to choose each.

pydanticdataclassbasemodeldata validation
A generic Pydantic model with a computed field, showing a type parameter T and a derived value appearing in serialized JSON output.
Python

Using Computed Fields with Generic Models in Pydantic

Learn how to combine Pydantic v2's computed_field with generic models: type parameter handling, serialization behavior, inheritance, custom serializers, and safe patterns.

Pydanticcomputed_fieldgeneric modelstype hints
Illustration of Pydantic ConfigDict controlling extra fields and strict mode in Python models
Python

Python Pydantic ConfigDict Extra Fields and Strict Mode

See how Pydantic ConfigDict's extra and strict settings control unknown fields and type coercion in Python models, with examples for API validation.

PydanticConfigDictExtra FieldsStrict Mode
A visual representation of a datetime object being validated by a custom Pydantic validator, with a clock and a shield.
Python

Python Pydantic Datetime and Custom Type Validation

Learn how to validate datetime fields in Pydantic v2: parse Unix timestamps, require timezone-aware values, and build reusable custom types.

PydanticDatetimeCustom TypesData Validation
Diagram showing a Pydantic model with nested model, list of models, and enum fields
Python

Python Pydantic Nested Models, Lists, and Enums

Learn how to define and validate nested models, lists of models, and enum fields in Pydantic with clear examples, including optional values and common pitfalls.

pydanticdata validationnested modelsenums