Skip to main content

Favorites

Hand-picked shortlists of pages grouped by task. Each list links to pages elsewhere on the site, ordered roughly by what to read first.

API scripting​

For scripts that call an HTTP API (GET/POST, status codes), parse and build JSON, clean, filter, map and reshape records, then post updates back, all in clear, well-structured code that's easy to adapt when requirements change. Clarity and organization matter more than algorithmic optimization.

HTTP & JSON​

  1. Structuring an API script: the layout and a full worked example. Start here.
  2. requests: GET/POST, params, json=, headers, timeouts, errors, Session.
  3. urllib.request: stdlib fallback if requests isn't installed.
  4. HTTP status codes: what each code means and how to react.
  5. json: loads/dumps, pretty-printing, default= for dates and dataclasses.
  6. Accessing nested JSON: .get chains, the null trap, match on payloads.
  7. Cleaning & transforming data: filter, normalize, coerce, dedupe, group, join, diff.
  8. Pagination, retries & batching: generators, backoff, batched, thread pools.
  9. Secure API scripting: secrets, TLS, injection, SSRF, redirects, HMAC, safe writes.
  10. Mock API server: a local fake API to practice against, plus unittest.mock.

Reshaping data​

Clean, structured scripts​

Extras worth a skim​

Checklist​

  • Pin down the task and the payload shapes; check auth, pagination and rate limits.
  • Make one request first and print it: status code, then json.dumps(r.json(), indent=2).
  • Check import requests works; if not, switch to urllib.request with a small helper.
  • Keep fetch, transform and post in separate functions; constants at the top; a main().
  • Always pass timeout=; check the status before calling .json(); handle 204 (no body).
  • Use .get() for optional fields and d.get("x") or {} for nullable nested objects.
  • POST one record and check the response before looping over all of them.
  • Don't let one bad record crash the run: log it, count failures, keep going.
  • Think about retries, idempotency, batching and parallelism, even if you don't build them yet.

Security habits​

  • Token from os.environ, sent in a header, never printed or logged; fail fast if it's missing.
  • HTTPS with verification on; timeouts, retry caps, page caps and response-size caps.
  • Validate every response field (type, shape, allowlisted values) before using it.
  • Build URLs with params= and quote(..., safe=""); log untrusted values with %r.
  • No auth on redirects to other hosts (allow_redirects=False); allowlist hosts for URLs from data.
  • POST only allowlisted fields; dry run by default with an --apply flag and a change limit.

Docs​