Python Client for Arista eAPI

1.0.4 · active · verified Fri Apr 17

pyeapi is a Python client library for interacting with Arista EOS devices via their eAPI. It provides a simple, Pythonic interface for sending commands, parsing responses, and managing network configurations. The current version is 1.0.4, with releases occurring periodically to address bugs and introduce minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to connect to an Arista EOS device using `pyeapi.connect` and execute simple 'show' commands. It uses environment variables as placeholders for credentials, which should be replaced with actual values or a `pyeapi.conf` file for production use. It then prints the device's EOS version, hostname, and the status of its network interfaces.

import pyeapi
import os

# Configure connection details (e.g., in a YAML file or environment variables)
# For quickstart, using environment variables as placeholders:
HOST = os.environ.get('PYEAPI_HOST', '10.0.0.1')
USERNAME = os.environ.get('PYEAPI_USERNAME', 'admin')
PASSWORD = os.environ.get('PYEAPI_PASSWORD', 'arista')

# A more robust setup would use a pyeapi.conf file or direct dictionary config
# For simplicity, we'll create a dictionary config for direct connection

node_config = {
    'transport': 'https',
    'host': HOST,
    'username': USERNAME,
    'password': PASSWORD,
    'port': 443,
    'timeout': 30
}

try:
    # Connect to the Arista EOS device
    node = pyeapi.connect(**node_config)
    print(f"Successfully connected to {HOST}")

    # Run a 'show version' command
    response = node.run_commands(['show version'])
    print("\n--- Device Version ---")
    print(f"EOS Version: {response[0]['version']}")
    print(f"Hostname: {response[0]['hostname']}")

    # Run a 'show interfaces' command
    interfaces_response = node.run_commands(['show interfaces'])
    print("\n--- Interfaces Status ---")
    for intf_name, intf_data in interfaces_response[0]['interfaces'].items():
        print(f"  {intf_name}: {intf_data['lineProtocolStatus']} (Admin: {intf_data['interfaceStatus']})")

except pyeapi.eapilib.EapiError as e:
    print(f"EAPI Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →