How I write Python
- HTTP: HTTPX. Why? One library for both sync and async. Easy to use a SOCKS proxy. Similar to requests but typed.
- DOM: Selectolax. Why? Faster than Beautiful Soup with html5lib and even html5-parser. Easier to install than html5-parser because it doesn’t require disabling binary wheels for lxml. The API more type-friendly.
- Time: Whenever. Why? Correctly handles DST and uses types to prevent mistakes. See “Ten Python datetime pitfalls, and what libraries are (not) doing about it”, Arie Bovenberg2024.
- XML: xmltodict. Why? The most fun I’ve had manipulating XML. Despite the name, xmltodict is bidirectional.
- URLs: yarl. Why? Percent-decodes paths. Nice API: the fields are named well, and it uses a
MultiDict
class appropriately.
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.
- “Deploying a distributed system? A type system helps a lot”, Spencer Baugh2021.
- “Algebraic Data Types in (typed) Python”, Tin Tvrtković2023
- “Writing Python like it’s Rust”, Jakub Beránek2023. The author’s style resembles the style I have arrived it.
- “Shape typing in Python”, Jim Fisher2024
- 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.”
- Python type checkers—my GitHub list
- “Awesome Python Typing”—a collection of links to software and articles