Web Development

Build web apps and services with tested examples: HTTP, REST APIs, servers, routing, and templating across the Python and Groovy tutorials.

Python: Type Hints, Annotations, Union Types (X | None), Generics

Python type hints let you write down what types a function expects and returns. This guide compares the annotation styles so you know which one to reach for: the modern X | None union syntax, container generics like list, TypeVar for generic functions, Protocol for structural subtyping, and the journey from the old typing.Optional to today’s native Python 3.10+ syntax. “Type hints are documentation that the computer can check.” Guido van Rossum Last Updated: July 2026 | Tested on: Python ... Read More

Python: Dataclasses, Modern Data Containers

A Python dataclass writes the boring parts of a class for you: the __init__, the __repr__, and the __eq__. You declare the fields once with type annotations, add @dataclass on top, and Python fills in the rest. This post is a recipe book of dataclass patterns: simple defaults, mutable default factories, frozen immutability, computed fields with __post_init__, and the memory savings from slots. “The best code is the code you never had to write.” Jeff Atwood, Coding Horror Last Updated: ... Read More

Python: Pydantic, Data Validation, Settings, Serialization

You wrote a clean API endpoint and it worked on your machine. Then someone sent "age": "twenty-eight" in a JSON body, your code did math on a string, and the request blew up three functions deep. The Python Pydantic library stops that at the door: v2 checks every field as data arrives, coerces "42" into a real 42, and raises one clear error naming the exact bad field. “There are two ways of constructing a software design: one way is ... Read More