Browse by Topic

Popular

Latest

Latest Python Posts

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
Illustration showing Pydantic model_validate converting external data into a typed model and model_dump converting it back to a dictionary
Python

Python Pydantic model_dump and model_validate Explained

Pydantic v2's model_validate() turns external data into a validated model, while model_dump() turns a model back into a plain dictionary. This guide covers when to use each method, how to include or exclude fields, and common mistakes.

pydanticpythonmodel-validationdata-serialization
Illustration of a Pydantic model with field names mapped to alias names during serialization, showing arrows from snake_case to camelCase and a JSON output.
Python

Python Pydantic Aliases and Serialization

Learn how Pydantic aliases affect serialization and how to use by_alias and populate_by_name to control field names in model_dump and JSON output.

pydanticaliasesserializationdata validation
Diagram showing a Pydantic model with an optional field using default_factory to generate a fresh mutable default.
Python

Python Pydantic Optional Fields: Defaults & default_factory

Learn how to define optional fields in Pydantic, what `Optional[T]` actually means, and how `default_factory` differs from a plain `default` for mutable default values.

PydanticPythonOptional FieldsDefault Values
Diagram showing a Pydantic model with field_validator applied to individual fields and model_validator applied to the whole model
Python

Pydantic field_validator and model_validator in Python

Learn how to use Pydantic's field_validator and model_validator for single-field and cross-field validation, including syntax and practical examples.

pydanticvalidationpythondata validation
Illustration of a Pydantic BaseModel schema validating incoming data fields with type checks and constraints.
Python

Python Pydantic BaseModel Fields and Validation

How Pydantic BaseModel fields validate data: type coercion, Field constraints, validators, nested models, error handling, and validation overhead.

pydanticpython validationdata modelingpython typing
Illustration comparing a direct API call with a layered framework approach in Python, showing two diverging paths from a single starting point.
Python

Python LangChain vs Direct OpenAI API: Which to Use

Compare Python LangChain and the direct OpenAI API for LLM calls: dependency footprint, debugging, orchestration features, and when to choose each.

LangChainOpenAI APIPythonLLM integration
Diagram of a Python LangChain chain connecting a prompt template to an OpenAI chat model with a streamed response.
Python

Python LangChain OpenAI Integration

Set up the Python LangChain OpenAI integration with ChatOpenAI: install the packages, configure the API key, build prompt chains, stream responses, handle errors, and plan for production.

LangChainOpenAIPythonChatOpenAI