Registry / http-networking / netmiko

netmiko

JSON →
library4.7.0pypypi✓ verified 21d ago

Netmiko is a multi-vendor Python library designed to simplify the process of establishing and managing CLI connections to network devices via SSH, Telnet, or Serial. It handles common networking tasks like sending commands, entering/exiting configuration modes, and transferring files. As of version 4.6.0, Netmiko is actively maintained, frequently adding new device drivers and enhancing existing functionality.

pip install netmiko
INSTALL
IMPORT
SIG · NETMIKO
N
netmiko
http-networkingpythonv4.7.0
Install
5.0s avg
Import
1050ms
Disk
67MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.7.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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.086s · 67.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.0s · import 1.014s · 68MB
67MB installed
● package 67MB
Code
Verified usage

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

ConnectHandler
from netmiko import ConnectHandler
NetmikoTimeoutException
from netmiko.exceptions import NetmikoTimeoutException
from netmiko.ssh_exceptions import NetmikoTimeoutException
The exceptions module was moved in Netmiko 4.0.0.
NetmikoAuthenticationException
from netmiko.exceptions import NetmikoAuthenticationException
from netmiko.ssh_exceptions import NetmikoAuthenticationException
The exceptions module was moved in Netmiko 4.0.0.

Connects to a network device using credentials from environment variables, sends a 'show ip int brief' command, and attempts to parse the output using TextFSM via `use_textfsm=True`. Remember to configure environment variables like NETMIKO_HOST, NETMIKO_USERNAME, NETMIKO_PASSWORD, and NETMIKO_DEVICE_TYPE before running.

import os from netmiko import ConnectHandler from netmiko.exceptions import NetmikoTimeoutException, NetmikoAuthenticationException # Define device parameters using environment variables for security device_ip = os.environ.get('NETMIKO_HOST', 'your_device_ip') username = os.environ.get('NETMIKO_USERNAME', 'your_username') password = os.environ.get('NETMIKO_PASSWORD', 'your_password') device_type = os.environ.get('NETMIKO_DEVICE_TYPE', 'cisco_ios') # e.g., cisco_ios, juniper, arista_eos, etc. if 'your_device_ip' in device_ip or not all([device_ip, username, password, device_type]): print("Please set NETMIKO_HOST, NETMIKO_USERNAME, NETMIKO_PASSWORD, and NETMIKO_DEVICE_TYPE environment variables, or update the placeholder values.") exit(1) device = { "device_type": device_type, "host": device_ip, "username": username, "password": password, # "optional_args": {"port": 22}, # Example for custom SSH port } try: print(f"Connecting to {device_ip}...") with ConnectHandler(**device) as net_connect: print("Successfully connected!") # Use use_textfsm=True to attempt structured output parsing output = net_connect.send_command("show ip int brief", use_textfsm=True) print("\n--- Output of 'show ip int brief' (parsed with TextFSM) ---\n") print(output) # Example for sending configuration commands # config_commands = ["interface loopback 0", "ip address 1.1.1.1 255.255.255.255"] # output_config = net_connect.send_config_set(config_commands) # print("\n--- Configuration Output ---\n") # print(output_config) net_connect.disconnect() print("Disconnected.") except NetmikoAuthenticationException: print("Authentication failed. Check username and password.") except NetmikoTimeoutException: print("Connection timed out. Check host IP and network connectivity.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThe exceptions module was relocated from `netmiko.ssh_exceptions` to `netmiko.exceptions`. Code relying on the old import path will break.
fix
Update import statements from `from netmiko.ssh_exceptions import ...` to `from netmiko.exceptions import ...`.
affects: 4.0.0 and later
breaking`send_command` and `send_command_timing` methods were refactored to primarily use the `read_timeout` argument. Older `delay_factor` based logic might behave differently, potentially causing unexpected timeouts or delays.
fix
Review code using `send_command` or `send_command_timing` and adjust `read_timeout` parameters as needed, understanding its direct impact on how long Netmiko waits for output. `delay_factor` is still available but `read_timeout` is preferred.
affects: 4.0.0 and later
breakingSupport for older Python versions is periodically dropped. Python 3.7 support was dropped in v4.3.0, and Python 3.8 support was dropped in v4.5.0. Netmiko 4.6.0 requires Python >= 3.9.
fix
Ensure your Python environment is running version 3.9 or higher to use Netmiko 4.6.0+.
affects: 4.3.0, 4.5.0 and later
gotchaWhile Netmiko includes `ntc-templates` (which uses `TextFSM`) for parsing, users often forget to enable structured output. By default, `send_command` returns raw string output. To get structured data for supported commands, you must use the `use_textfsm=True` argument.
fix
When calling `send_command`, add `use_textfsm=True` to automatically parse output using available NTC templates. Example: `net_connect.send_command('show ip int brief', use_textfsm=True)`.
affects: All versions
gotchaThe `session_log` functionality, while intended to hide sensitive information like passwords, has had scenarios where it failed to do so. It should always be treated as a security-sensitive file and carefully managed.
fix
Carefully review `session_log` files for sensitive data before sharing. Consider limiting its use or implementing stricter log management practices like secure storage and access controls.
affects: All versions, specifically addressed in 4.3.0 but remains a caution
gotchaPython 3.13 removed `telnetlib` from its standard library. Netmiko v4.4.0 vendorized `telnetlib` internally to maintain Telnet support. Users on older Netmiko versions (prior to 4.4.0) attempting to use Telnet with Python 3.13 would encounter import errors.
fix
Upgrade Netmiko to version 4.4.0 or newer if using Python 3.13 and requiring Telnet functionality.
affects: 3.x to 4.3.x when used with Python 3.13
Errors
Common errors & fixes
netmiko.ssh_exception.NetmikoAuthenticationException: Authentication to device failed.
This error occurs when the username, password, or SSH key provided for authentication is incorrect, or if there's a problem connecting to the specified device with those credentials.
fix
Verify the username and password (or SSH key) for the target device. Ensure the `device_type` parameter is correctly specified and that there are no firewall rules blocking the connection. Implement a `try-except` block to gracefully handle this exception.
netmiko.ssh_exception.NetmikoTimeoutException: Paramiko: 'No existing session' error: try increasing 'conn_timeout' to 10 seconds or larger.
This timeout error indicates that Netmiko could not establish an SSH session within the default or specified connection timeout period. This often happens due to network latency, an unreachable device, or a slow-responding device.
fix
Increase the `conn_timeout` and/or `read_timeout` parameters in the `ConnectHandler` call to allow more time for the connection to establish and for command output to be received. Wrap the connection attempt in a `try-except NetmikoTimeoutException` block.
ModuleNotFoundError: No module named 'netmiko'
The Python interpreter being used cannot find the Netmiko library. This typically means Netmiko is not installed in the active Python environment or there's a mismatch between where it's installed and where Python is looking.
fix
Install Netmiko using `pip install netmiko` (or `pip3 install netmiko` for Python 3). Ensure you are running your script with the Python interpreter where Netmiko was installed, possibly within a virtual environment.
ValueError: Unsupported 'device_type'
This error means that the `device_type` string provided to Netmiko's `ConnectHandler` is not recognized or supported. This could be due to a typo, incorrect casing, or an unsupported device.
fix
Check the Netmiko documentation for the exact list of supported `device_type` strings and ensure the value used matches one of them (e.g., `cisco_ios` instead of `Cisco_ios`).
EOFError: Channel stream closed by remote device.
This error signifies that the SSH channel was unexpectedly closed by the remote network device. Common causes include an explicit 'exit' command being sent prematurely, an idle timeout on the device, resource issues on the device, or an unstable network connection.
fix
Review the commands sent to the device to ensure no `exit` command is unexpectedly terminating the session. Increase the `read_timeout` parameter. Check the device's logs for reasons it might be closing SSH connections, such as session limits or idle timeouts.
Upgrade
Version history
4.7.0latest on PyPI · released May 12, 2026
Audit
Dependencies
paramikorequiredSSH client library for secure shell connections.
pyserialrequiredSerial port backend for console connections.
scprequiredSCP client for secure file transfers.
ntc-templatesrequiredCollection of TextFSM templates for parsing structured output from network devices.
Agent activity
9 hits · last 30 days
node
8
Resources
netmiko — pip install netmiko · libregistry