Registry / http-networking / pyeapi

pyeapi

JSON →
library1.0.4pypypi✓ verified 88d ago

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.

pip install pyeapi
INSTALL
IMPORT
SIG · PYEAPI
P
pyeapi
http-networkingpythonv1.0.4
Install
2.8s avg
Import
148ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.153s · 29.7MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 2.8s · import 0.142s · 30MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Node
✓ from pyeapi.client import Node
✗ import pyeapi.client.Node
The Node class is typically imported directly from pyeapi.client for ease of use, rather than accessing it as an attribute of the pyeapi.client module.
connect
✓ import pyeapi node = pyeapi.connect(host='10.0.0.1')
The connect function is a top-level function of the pyeapi package, used to establish a connection to an Arista EOS device.

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}")
Debug
Known issues
breakingpyeapi v1.0.0 and later are Python 3 only. Python 2.7 is no longer supported.
fix
Upgrade to Python 3.7 or newer. If you must use Python 2, use pyeapi versions prior to 1.0.0 (e.g., 0.8.x).
affects: >=1.0.0
breakingpyeapi v1.0.0 and later require Python 3.7 as the minimum supported Python version.
fix
Ensure your environment uses Python 3.7 or a later 3.x release. Check your Python version with `python --version`.
affects: >=1.0.0
gotchaFor on-box deployments (pyeapi running directly on the Arista switch), Arista EOS 4.22 or later is required for pyeapi v1.0.0+.
fix
Upgrade your Arista EOS version to 4.22 or newer if running pyeapi on the switch itself. This limitation does not apply to off-box usage.
affects: >=1.0.0
gotchaVersion 1.0.2 provided a critical bug fix. It is strongly advised to upgrade to 1.0.2 or later to avoid potential issues introduced in earlier 1.x releases.
fix
Upgrade pyeapi to version 1.0.2 or the latest available stable release using `pip install --upgrade pyeapi`.
affects: 1.0.0, 1.0.1
Errors
Common errors & fixes
No module named 'pyeapi'
The pyeapi library is not installed in the active Python environment.
fix
Install the library using pip: `pip install pyeapi`.
pyeapi.eapilib.EapiError: Failed to connect to eAPI: Connection refused
The eAPI service is not running or accessible on the target device, or there's a network connectivity issue (firewall, routing).
fix
Verify network connectivity to the device (e.g., `ping`). Ensure eAPI is enabled on the Arista switch (`management api http-command` or `management api https-command` in config mode). Check firewall rules and the specified port (default 80 for HTTP, 443 for HTTPS).
pyeapi.eapilib.EapiError: Failed to connect to eAPI: Authentication failed
Incorrect username or password provided for the eAPI connection.
fix
Double-check the username and password configured for eAPI access on the Arista switch. Ensure they match the credentials passed to `pyeapi.connect`.
pyeapi.eapilib.EapiError: 'interface Ethernet1' failed with error 'Invalid command'
The command sent to the device is syntactically incorrect, not supported, or used in the wrong mode for the current eAPI context.
fix
Review the exact command syntax for Arista EOS. Test the command directly on the switch CLI to ensure it's valid. Some commands require 'enable' mode or specific configuration contexts.
Upgrade
Version history
1.0.4latest on PyPI · released Aug 20, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pyeapi — pip install pyeapi · libregistry