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

3D illustration of three cubes on a balance scale, one with a validation shield, one with a speed arrow, one translucent
Python

Pydantic v2 vs dataclasses vs TypedDict: Speed and Memory

TypedDict validates nothing, a dataclass accepts the wrong type, and Pydantic pays for a compiled validator. A reproducible benchmark and where each belongs.

PythonPydanticPerformanceData Modeling
3D illustration of a circular event loop ring with a jammed amber brick and a closed padlock node
Python

Python asyncio: Event Loop Is Closed and Blocking Calls

asyncio.run closes its loop, so a cached client or pool dies with the second call. Where the loop lifetime belongs, and how to keep blocking IO from stalling every task.

PythonasyncioConcurrencyDebugging
3D illustration of CSV row slabs folding into JSON brace objects with a BOM tag pulled away
Python

CSV to JSON in Python: Encoding, Types, and Serialization Pitfalls

CSV has no types, so every conversion is a guess. Four settings decide whether the output is faithful: the encoding, the newline mode, the dialect, and how NaN is serialized.

PythonCSVJSONData Processing
3D illustration of a request card rejected at a validation gate with an error list panel
Python

FastAPI 422: Custom Validation Errors and Response Models

Three exceptions share the 422 path and only one is handled by default. A single handler that strips input and flattens loc gives clients a contract that survives a Pydantic version change.

PythonFastAPIPydanticAPI Design
3D illustration of dependency cubes resolved through a solver funnel into a lockfile slab
Python

uv Resolution Errors: Reading No solution found and Lock Drift

The last Because clause is the contradiction and everything above it is context. Then decide: relax a pin, narrow requires-python, or change index strategy.

PythonuvDependenciesPackaging
Python 3.12 generic class Box with T and U type parameter slots
Python

Python 3.12 Generics: PEP 695 Syntax, Type Parameters, and TypeVar

How Python 3.12 PEP 695 type parameter syntax works: bracket declarations for classes, functions, and type aliases, bounds and constraints, inferred variance, lazy evaluation, and the runtime scope rules.

PythonGenericsType HintsPEP 695
Python asyncio event loop with tasks connected in a ring
Python

Python Asyncio: Event Loop and Tasks Explained

How the asyncio event loop schedules coroutines and tasks in Python, with concurrency patterns, TaskGroup, cancellation, timeouts, and the failure modes that break production services.

PythonAsyncioConcurrencyEvent Loop
Comparison of two Python Kafka client libraries with code snippets and a scale icon.
Python

Python Kafka: kafka-python vs Confluent Client

kafka-python is pure Python; confluent-kafka wraps librdkafka. Compare APIs, throughput, error handling, and pick the client that fits your service.

KafkaPythonkafka-pythonConfluent
Illustration of a Python Kafka producer and consumer connected through a Schema Registry with Avro schemas, showing data flow and schema validation.
Python

Python Confluent Kafka Producer Consumer and Schema Registry

python confluent kafka producer consumer and schema registry: Learn to build a Python Kafka producer and consumer with Confluent's client and Schema Registry, covering...

KafkaConfluentSchema RegistryAvro
Illustration of Kafka partition offsets and manual commit flow in a Python consumer
Python

Python Kafka Offsets, Partitions, and Manual Commits

Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.

KafkaPythonOffsetsPartitions