Python

asyncormpathsqltesting

Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.

Language deep dives

  • Decorators - wrapping callables (with functools.wraps, arguments, stacking, and the kinds of decorators).
  • Descriptors - the __get__/__set__ protocol behind properties, methods and ORM fields.

Web frameworks

  • Python Web Frameworks - the field compared: Django, FastAPI, Flask, Litestar, Starlette.
  • Django - the batteries-included framework: query and migration cookbook, ORM gotchas, async limits (see also Django authentication).
  • FastAPI and Starlette - the async, type-hinted stack (FastAPI builds on Starlette).
  • aiohttp - async HTTP client and server, the non-ASGI branch of the async world.
  • Jinja2 - templating: undefined values, whitespace, macros, and the defaults that bite.
  • WTForms - form handling and validation (a legacy choice today).

Data and libraries

  • Pandas - data wrangling, and the defaults that quietly change a result.
  • Jupyter - notebooks: running them from the command line, kernels, hidden state.
  • SQLAlchemy - SQL toolkit and ORM (see also Databases).
  • Odoo - the ERP framework.
  • Bonobo - ETL toolkit (not maintained for now).

Testing

  • Testing with Python - pytest in practice: project layout, fixtures, parametrization, mocking, coverage, and the collection gotchas that pass in silence.

Cookbook

Compute the directory of the current file:

from pathlib import Path

HERE = Path(__file__).resolve().parent

Older recipes join __file__ to os.getcwd() first. That was for the script run from the command line, whose __file__ used to be relative: since Python 3.9 it is absolute too, so the join is a no-op (checked on 3.15, from two different working directories). resolve() is still worth keeping, it follows symlinks.

Related

Keyboard shortcuts

/Open search
CtrlKOpen search (Cmd+K on macOS)
?Show this cheat sheet
Ctrl/Show this cheat sheet (Cmd+/ on macOS)
EscClose search or this cheat sheet

Turns off the single-key shortcuts (/, ?). Ctrl/Cmd+K and Ctrl/Cmd+/ stay.