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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.153s · 29.7MB
glibcpy 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}")
Errors
Common errors & fixes
No module named 'pyeapi'
The pyeapi library is not installed in the active Python environment.
fixInstall 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).
fixVerify 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.
fixDouble-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.
fixReview 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.