Automation · Python Automation
API Automation
Cheat sheet · https://pcornel.dk/topic.php?topic=5272
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
| Layer | Python Automation → API Automation operational reference |
|---|---|
| Runtime/ownership | Python API automation / standard-library HTTP client patterns · identify controller/parser, durable intent, identity and target ownership before mutation |
| Persistent intent | Versioned definition/configuration with explicit dependencies, scope and credential boundary |
| Verification | python -X dev api_probe.py --base-url <fixture> --dry-run; capture status, headers, request ID and parsed response schema. |
| Expected interpretation | Requests target the intended endpoint with explicit timeout/authentication, validate response status/schema, handle retries only for safe/idempotent cases, and preserve correlation IDs. |
| Recovery boundary | Preserve 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