Install & Compatibility
Where this runs
tested against v5.1.0 · 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.920 runs
installs and imports cleanly · install 0.0s · import 6.481s · 139.7MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 11.0s · import 7.056s · 140MB
125MB installed
● package 125MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
get_network_driver
✓ from napalm import get_network_driver
NapalmBaseException
✓ from napalm.base.exceptions import NapalmBaseException
✗ from napalm.exceptions import NapalmBaseException
Exceptions are located under `napalm.base.exceptions` since v3.x.
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)
napalm --version
Errors
Common errors & fixes
napalm.base.exceptions.ConnectionException: Cannot connect to device 192.168.1.1
Network connectivity issues, incorrect hostname/IP, wrong port, firewall blocking, or invalid device credentials/access method.
fixVerify network reachability (ping), check SSH/API port (default 22 for SSH, 443/830 for API/NETCONF), ensure correct username/password, and confirm device is configured for programmatic access (SSH, API enabled, correct user privileges).
TypeError: 'NoneType' object is not callable (e.g., when calling `get_network_driver('nonexistent_driver')`)
The specified network driver name is incorrect, unsupported, or a required underlying dependency for the driver is not installed.
fixDouble-check the driver name against NAPALM's documentation (e.g., 'ios', 'eos', 'junos', 'nxos'). If it's a valid driver, ensure all necessary optional dependencies (e.g., `pip install napalm[full]` or specific driver extras) are installed.
napalm.base.exceptions.MergeConfigException: Configuration validation failed: ... (followed by device error messages)
The configuration payload provided to `load_merge_candidate` or `load_replace_candidate` contains syntax errors or conflicts with the device's current configuration.
fixReview the configuration changes being pushed. Test the configuration snippet manually on the device CLI to ensure it's valid. Inspect the device's error messages for specific syntax issues.
napalm.base.exceptions.LockError: Unable to lock device's configuration
Another process or user has an exclusive lock on the device's configuration, preventing NAPALM from making changes.
fixWait for the other process/user to release the lock, or manually clear the lock on the device if no active changes are being performed. In some cases, increasing the `lock_config_timeout` optional argument might help if the device is slow to respond.
Upgrade
Version history
5.1.0latest on PyPI · released Aug 5, 2025
Audit
Dependencies
netmikorequiredUnderlying SSH/Telnet library for many drivers
pyeapioptionalArista EOS driver
junos-ezncoptionalJuniper Junos driver
ncclientoptionalNETCONF protocol support for various drivers