JCPA study materials
JCPA study resources

JCPA: Python Programming for Network Automation

JCPA · Work through your exam, one topic at a time.

All guide sections

Python Programming for Network Automation

Candidates need working Python literacy, not software-engineering depth. Focus on: data types (str, int, list, dict, tuple, set), control flow, functions, modules/imports, exception handling (try/except/finally), file I/O, and the standard library modules used in automation - json, xml.etree.ElementTree (or lxml), re, subprocess, and os/pathlib.

Understand dicts as the backbone of structured data: nested dictionaries and lists map directly to JSON/YANG-modeled device data, so you must be able to read a nested structure and extract a value by key path. Know string formatting (f-strings), list comprehensions at a reading level, and how to iterate over a list of devices and apply the same operation - the classic loop-with-error-handling pattern.

Traps that appear in questions: mutable default arguments; modifying a list while iterating it; assuming except: is good practice (it is not - catch specific exceptions); confusing == with is; and forgetting that JSON keys are always strings. Also expect questions on reading credentials from environment variables rather than hardcoding them, and on using with open(...) so files close reliably.

Libraries to recognize by purpose: Junos PyEZ (jnpr.junos), Requests (HTTP/REST), ncclient (NETCONF), Paramiko (SSH), Jinja2 (templating), NAPALM (multi-vendor abstraction). You do not need to write complex code, but you must predict what a short snippet does and spot the bug.

Worked example:

for dev in devices:
    try:
        connect_and_push(dev)
    except ConnectionError as e:
        log.error(f"{dev['host']} failed: {e}")
        continue

This isolates per-device failures so one unreachable device does not abort the whole run - a frequent exam scenario.