Python Automation
Cheat sheet · https://pcornel.dk/topic.php?topic=785
Answer
Python automation combines typed data structures, functions, libraries and exception handling to call APIs or device transports predictably.
Remember
- Parse structured JSON/XML instead of screen-scraping where possible
- Set timeouts and check status/error bodies explicitly
- Separate secrets/configuration from code; validate TLS and host keys
- Make changes idempotent, bounded and testable
- Exceptions must preserve context without leaking credentials.
First checks
python3 --version— interpreterpython3 -m venv .venv && . .venv/bin/activate— isolated envruff check . && pytest— lint and tests
Verify in this order
script/package → venv → libraries → targets
Where it usually breaks
A successful function or HTTP response does not prove semantic correctness, idempotency or safe device state.
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Python for Network Automation evidence chain
| Boundary | Question | Evidence | Does not prove |
|---|---|---|---|
| Definition | What is configured or intended? | running configuration / controller policy | live operation |
| Local state | Is the feature active at the expected scope? | python -m pytest | remote success |
| Counters | Did controlled traffic or an event reach this stage? | scoped counters/timestamps | complete return path |
| Next boundary | What consumes or transports this state? | input/schema → authenticated client → request/transport → structured response → validation/diff → bounded change → verification | application success |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=785