Essential Libraries Highlights Summary
Every highlight bullet from the 12 pages in this section, gathered on one page and grouped by the page it came from.
- The standard library is a broad, stable floor - PyPI is where domain depth and speed actually live
- A virtual environment isolates one project's dependency graph from every other project on the machine
- The strongest place to reach for a dependency is a boundary - request bodies, env vars, scraped HTML - not deep inside business logic
- A version pin in pyproject.toml is a promise a maintainer makes, not a guarantee your installer enforces on its own
- Every added dependency is also added attack surface and maintenance liability, not just added capability
- httpx mirrors requests API and adds async, HTTP/2, and timeouts
- Always set connect/read timeouts - never rely on infinite defaults
- Use context managers or client instances for connection pooling
- raise_for_status() after calls; map HTTP errors to domain exceptions
- Prefer httpx for new code; keep requests only where migration cost is high
- Rich formats tables, progress bars, and tracebacks without ANSI boilerplate
- Textual builds full terminal UIs with widgets and async event loops
- Use Console.print() instead of print() for structured CLI output
- Log to stderr; reserve stdout for machine-readable pipe data
- Textual apps need explicit keyboard and resize handling
- BaseSettings loads and validates env vars at import/startup
- Field aliases map DATABASE_URL-style names to Python attributes
- Fail fast on missing required secrets before serving traffic
- Use model_config for env file paths and nested delimiter
- Separate Settings per deployable - do not share one god object
- Decorator-based retries with exponential backoff and jitter
- Retry only on specific exceptions - not blanket catch-all
- stop_after_attempt caps total tries; stop_after_delay caps wall time
- Idempotent operations only unless you implement deduplication
- Log before_sleep to make retry storms visible in observability
- pendulum and arrow wrap stdlib datetime with human-friendly APIs
- Prefer zoneinfo + datetime for new code when possible
- Always store UTC in databases; convert at display boundaries
- Parsing user input needs explicit timezone or offset
- Avoid naive datetime arithmetic across DST boundaries
- Pillow (PIL fork) opens, transforms, and saves raster images
- Always close images or use context managers to free handles
- EXIF orientation must be applied before resize/thumbnail
- Prefer thumbnail() for web previews - preserves aspect ratio
- Validate upload MIME and size before Pillow decode (decompression bombs)
- openpyxl reads/writes Excel xlsx without Excel installed
- python-docx builds Word documents from templates
- reportlab generates PDFs programmatically for invoices and reports
- Never trust uploaded office files - scan size and macro risk
- For complex layouts, start from a template file rather than zero code
- BeautifulSoup provides a forgiving DOM API over html.parser or lxml
- lxml is faster and stricter - good for large documents and XPath
- Respect robots.txt, rate limits, and terms of service
- Prefer official APIs over scraping when available
- Never use scraped HTML with innerHTML-equivalent without sanitization
- Celery workers execute async tasks from a broker (Redis/RabbitMQ)
- Tasks must be idempotent - retries are normal
- JSON serialization only for JSON-serializable payloads
- Separate broker URL, result backend, and beat scheduler config
- FastAPI BackgroundTasks for in-process work; Celery for cross-process scale
- SQLAlchemy is the core ORM/SQL toolkit for Python
- SQLModel combines SQLAlchemy tables with Pydantic models
- Use 2.0 style select() and session.execute - not legacy Query
- Migrations belong in Alembic - not manual CREATE in app code
- See databases section for deep coverage - this page orients essentials
- Prefer httpx with explicit timeouts over one-shot requests calls
- Validate env config with pydantic-settings at startup
- Retry only idempotent operations with tenacity
- Store UTC timestamps; parse timezones at boundaries
- Cap upload bytes before Pillow decode
- Use Celery for cross-process work, not long HTTP handlers
Reviewed by Chris St. John·Last updated Jul 31, 2026