NAPALM: Network Automation and Programmability Abstraction Layer with Multivendor Support

5.1.0 · active · verified Thu Apr 16

NAPALM (Network Automation and Programmability Abstraction Layer with Multivendor support) is a Python library that provides a unified API to interact with various network devices from different vendors (e.g., Cisco IOS/XR/NX-OS, Arista EOS, Juniper Junos). It abstracts away vendor-specific complexities, offering a consistent way to retrieve operational data and manage configurations. The current version is 5.1.0, with regular releases, typically major updates every 6-12 months and minor/patch releases in between.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a network device using NAPALM, retrieve basic device facts, and properly close the connection. Remember to replace the placeholder credentials and device type with your actual network environment details. For production, use environment variables or a secure credential management system.

from napalm import get_network_driver

def connect_and_get_facts(hostname, username, password):
    try:
        driver = get_network_driver("ios") # Replace 'ios' with your device type (e.g., 'eos', 'junos', 'nxos')
        device = driver(
            hostname,
            username,
            password,
            optional_args={
                "port": 22, # Or 830 for NETCONF, 443 for API
                "secret": "", # If using privilege escalation
                "config_file": None # Path to an external config file
            }
        )
        print(f"Connecting to {hostname}...")
        device.open()
        print(f"Successfully connected to {hostname}.")
        
        facts = device.get_facts()
        print("Device Facts:")
        for k, v in facts.items():
            print(f"  {k}: {v}")
            
        # Example: Get interface details
        # interfaces = device.get_interfaces()
        # print("Interfaces:", interfaces)
            
    except Exception as e:
        print(f"Error connecting or retrieving data: {e}")
    finally:
        if 'device' in locals() and device.is_open:
            device.close()
            print(f"Disconnected from {hostname}.")

if __name__ == "__main__":
    # Replace with your actual device details
    DEVICE_HOSTNAME = os.environ.get('NAPALM_TEST_HOSTNAME', '192.168.1.1')
    DEVICE_USERNAME = os.environ.get('NAPALM_TEST_USERNAME', 'admin')
    DEVICE_PASSWORD = os.environ.get('NAPALM_TEST_PASSWORD', 'password')
    
    # Make sure to set these environment variables or change the default values
    connect_and_get_facts(DEVICE_HOSTNAME, DEVICE_USERNAME, DEVICE_PASSWORD)

view raw JSON →