CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ncclient

Python library for NETCONF clients with support for SSH, TLS, and device-specific operations

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

NCClient

A 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.

Package Information

  • Package Name: ncclient
  • Language: Python
  • Installation: pip install ncclient

Core Imports

import ncclient
from ncclient import manager

For device-specific operations:

from ncclient import operations
from ncclient import transport
from ncclient import capabilities

Basic Usage

from 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()

Architecture

NCClient's architecture provides layered abstraction for NETCONF client operations:

  • Manager: High-level interface that orchestrates NETCONF sessions and operations
  • Operations: NETCONF RPC operations (get-config, edit-config, lock, etc.)
  • Transport: Communication layers (SSH, TLS, Unix sockets) with device-specific handlers
  • Device Handlers: Vendor-specific customizations for Cisco, Juniper, Huawei, etc.
  • XML Utilities: XML parsing and manipulation tools for NETCONF payloads

This design enables device-agnostic NETCONF operations while supporting vendor-specific optimizations and features.

Capabilities

Connection Management

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): ...

Connection Management

NETCONF Operations

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): ...

NETCONF Operations

Transport Layer

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: ...

Transport Layer

Device Support

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: ...

Device Support

XML Utilities

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"): ...

XML Utilities

Common Types

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): ...

docs

connection-management.md

device-support.md

index.md

netconf-operations.md

transport-layer.md

xml-utilities.md

tile.json