pythonista.rocks Notes from a working Pythonista
Search · RSS
  • Working with dates and times in Python: a practical guide

    2026-07-10 ·7 min read

    Python's datetime module is powerful but has a well-known pitfall: naive datetimes lack timezone info, which causes subtle bugs and outright errors when mixing them with timezone-aware datetimes. This guide covers the full datetime workflow in Python 3.9+, from basic object creation and string formatting to correct timezone handling with zoneinfo and arithmetic with timedelta. The core takeaway is to always use UTC-aware datetimes internally and convert to local time only for display.

    #python #datetime #timezones #zoneinfo #dst #python3 #standard library

  • Enforce API contracts at the boundary: Pydantic v2 validators done right

    2026-07-10 ·3 min read

    Pydantic v2 silently breaks several v1 assumptions - Optional[str] fields are now required unless you add = None, model validators return None instead of the instance if you forget return self, and lax mode will coerce "3" into an int without complaint. This article walks through field validators, cross-field model validators, and ConfigDict(strict=True) with runnable examples that expose exactly where these traps fire and how to close them.

    #python #api #pydantic #validation #pydantic-v2 #data-validation #rest-api

© pythonista.rocks  ·  About  ·  Contact  ·  Privacy  ·  Editorial policy