How I write Python

HTTPX.

  • One library for both sync and async
  • Easy to use a SOCKS proxy
  • Similar to requests but typed

Selectolax.

markdown-it-py.

  • Complies with the CommonMark standard
  • Typed
  • Faster than other CommonMark libraries in pure Python

Whenever.

  • Correctly handles DST
  • Uses types to prevent mistakes

See “Ten Python datetime pitfalls, and what libraries are (not) doing about it”, Arie Bovenberg2024.

yarl.

  • Percent-decodes paths
  • Nice API:
    • Fields are named well
    • Query parameters are stored in a MultiDict

xmltodict.

  • More fun than any other XML library
  • Parses and generates XML. (Despite the name, xmltodict is bidirectional.)

Python has robust optional static typing. If you took a break from Python in the mid-2010s like I did, it may come as a surprise. This page links to resources for writing statically-typed Python, plus a few that make use of type hints at runtime.

  • jsonargparse—“Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables”
  • Typed Argument Parser (Tap)—“Typed argument parser for Python”
  • Typer—“Typer, build great CLIs. Easy to code. Based on Python type hints.”
  • tyro—“Zero-effort CLI interfaces & config objects, from types”

  • poltergeist—“Rust-like error handling in Python, with type-safety in mind.”