Pcornel
Automation

Python Automation

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

Back to the Topic

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 — interpreter
  • python3 -m venv .venv && . .venv/bin/activate — isolated env
  • ruff 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

BoundaryQuestionEvidenceDoes not prove
DefinitionWhat is configured or intended?running configuration / controller policylive operation
Local stateIs the feature active at the expected scope?python -m pytestremote success
CountersDid controlled traffic or an event reach this stage?scoped counters/timestampscomplete return path
Next boundaryWhat consumes or transports this state?input/schema → authenticated client → request/transport → structured response → validation/diff → bounded change → verificationapplication success

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

Confirmation

Confirm action

Continue?