Pcornel
Automation · Python Automation

API Automation

Cheat sheet · https://pcornel.dk/topic.php?topic=5272

Back to the Topic

Answer

API automation in Python calls REST APIs with requests or httpx, handling authentication, pagination, rate limits, retries and JSON parsing, often wrapped in a small client class.

Remember

  • requests or httpx.
  • Auth, pagination, retries.
  • Check status codes.

First checks

  • python3 -c "import requests;print(requests.get('<api>/health',timeout=10).json())" — API call
  • Pagination handling — complete results
  • Rate limit/backoff handling — resilience

Verify in this order

script → authenticated API calls → paginated results

Where it usually breaks

Client payload/auth → HTTP transport → endpoint validation/policy → request accepted → queued/job execution → target mutation → effective state → consumer workload.

Python Automation → API Automation · operational reference

LayerPython Automation → API Automation operational reference
Runtime/ownershipPython API automation / standard-library HTTP client patterns · identify controller/parser, durable intent, identity and target ownership before mutation
Persistent intentVersioned definition/configuration with explicit dependencies, scope and credential boundary
Verificationpython -X dev api_probe.py --base-url <fixture> --dry-run; capture status, headers, request ID and parsed response schema.
Expected interpretationRequests target the intended endpoint with explicit timeout/authentication, validate response status/schema, handle retries only for safe/idempotent cases, and preserve correlation IDs.
Recovery boundaryPreserve correlation IDs + pre-state, repair first failing boundary, then verify the target independently

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5272

Confirmation

Confirm action

Continue?