Python library for NETCONF clients with support for SSH, TLS, and device-specific operations
npx @tessl/cli install tessl/pypi-ncclient@0.7.0A Python library for NETCONF (Network Configuration Protocol) clients. NCClient provides a comprehensive interface for managing network devices through the standardized NETCONF protocol, supporting multiple transport methods (SSH, TLS, Unix sockets) and device-specific optimizations for major network equipment vendors.
pip install ncclientimport ncclient
from ncclient import managerFor device-specific operations:
from ncclient import operations
from ncclient import transport
from ncclient import capabilitiesfrom ncclient import manager
# Connect to a NETCONF device
with manager.connect(
host='192.168.1.1',
username='admin',
password='admin',
hostkey_verify=False
) as m:
# Get server capabilities
for capability in m.server_capabilities:
print(capability)
# Get configuration
config = m.get_config(source='running')
print(config)
# Edit configuration
config_xml = '''
<config>
<interface xmlns="urn:example:interface">
<name>eth0</name>
<description>Management Interface</description>
</interface>
</config>
'''
m.edit_config(target='candidate', config=config_xml)
m.commit()NCClient's architecture provides layered abstraction for NETCONF client operations:
This design enables device-agnostic NETCONF operations while supporting vendor-specific optimizations and features.
Functions for establishing and managing NETCONF sessions over various transport protocols, with support for device-specific parameters and authentication methods.
def connect(host=None, port=830, username=None, password=None, **kwargs): ...
def connect_ssh(host, port=830, username=None, password=None, **kwargs): ...
def connect_tls(host, port=6513, **kwargs): ...
def connect_uds(path, **kwargs): ...Complete implementation of NETCONF standard operations for configuration management, datastore operations, and session control with vendor-specific extensions.
def get_config(source, filter=None, **kwargs): ...
def edit_config(target, config, **kwargs): ...
def get(filter=None, **kwargs): ...
def commit(**kwargs): ...
def lock(target): ...
def unlock(target): ...Low-level transport implementations supporting SSH, TLS, and Unix domain sockets with connection multiplexing and session management.
class SSHSession: ...
class TLSSession: ...
class UnixSocketSession: ...
class LibSSHSession: ...Device-specific handlers providing optimizations and vendor-specific functionality for major network equipment manufacturers.
def make_device_handler(device_params, ignore_errors=None): ...
class JunosDeviceHandler: ...
class NexusDeviceHandler: ...
class IosxrDeviceHandler: ...Tools for creating, parsing, and manipulating XML documents and NETCONF payloads with namespace support.
def new_ele(tag, attrs=None, **extra): ...
def sub_ele(parent, tag, attrs=None, **extra): ...
def parse_root(raw): ...
def to_xml(ele, encoding="UTF-8"): ...class NCClientError(Exception):
"""Base exception class for all NCClient errors."""
class RPCError(NCClientError):
"""NETCONF RPC error response."""
class OperationError(NCClientError):
"""Operation execution error."""
class TransportError(NCClientError):
"""Transport layer error."""
class Capabilities:
"""Represents the set of capabilities available to a NETCONF client or server."""
def add(self, uri): ...
def remove(self, uri): ...
def __contains__(self, key): ...
def __iter__(self): ...
class Capability:
"""Represents a single NETCONF capability."""
def __init__(self, namespace_uri, parameters=None): ...
@classmethod
def from_uri(cls, uri): ...