Registry / testing / yang.connector

yang.connector

JSON →
library26.5pypypiunverified

YANG Connector is a Python package providing tools for testing YANG models via NETCONF and RESTCONF protocols. Primarily, it offers a NETCONF client by wrapping the `ncclient` library and integrates seamlessly with the pyATS framework. The library is actively maintained, with the current version being 26.3, and supports NETCONF v1.0 and v1.1.

pip install yang.connector
INSTALL
IMPORT
SIG · YANG.CONNECTOR
Y
yang.connector
testingpythonv26.5
Install
4.5s avg
Import
Disk
74MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.5 · 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
glibc
py 3.10
✓ —
✓ 5.63s
py 3.11
✓ —
✓ 4.68s
py 3.12
✓ —
✓ 3.8s
py 3.13
✓ —
✓ 4.03s
py 3.9
3/4 runs
3/4 runs
74MB installed
● package 74MB
Code
Verified usage

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

Netconf
from yang.connector import Netconf
from yang import Netconf

This quickstart demonstrates how to connect to a network device using `yang.connector.Netconf` via the pyATS testbed loader. It then retrieves a filtered configuration (e.g., interfaces) and lists the device's NETCONF capabilities. Credentials should be provided via environment variables for security.

import os from pyats.topology import loader # Define device connection details using environment variables for security DEVICE_IP = os.environ.get('YANG_CONNECTOR_DEVICE_IP', 'your_device_ip') DEVICE_PORT = int(os.environ.get('YANG_CONNECTOR_DEVICE_PORT', 830)) # Default NETCONF port USERNAME = os.environ.get('YANG_CONNECTOR_USERNAME', 'admin') PASSWORD = os.environ.get('YANG_CONNECTOR_PASSWORD', 'admin') # A minimal pyATS Testbed YAML string for demonstration testbed_yaml = f''' devices: my_device: os: iosxe connections: netconf: class: yang.connector.Netconf ip: {DEVICE_IP} port: {DEVICE_PORT} protocol: netconf credentials: default: username: {USERNAME} password: {PASSWORD} ''' try: # Load the testbed from the YAML string testbed = loader.load(testbed_yaml) device = testbed.devices['my_device'] # Establish connection device.connect(via='netconf', init_exec_alias=False) print(f"Successfully connected to {device.name} via NETCONF.") # Example: Get configuration using get_config() # For a full configuration, an empty filter can be used # For specific data, provide an XML filter string filter_xml = '<filter type="subtree"><interfaces/></filter>' config_data = device.netconf.get_config(source='running', filter=filter_xml) print("\nRetrieved configuration (filtered for interfaces):\n") print(config_data.data_xml) # Example: Get capabilities print("\nServer Capabilities:") for cap in device.netconf.server_capabilities: print(f"- {cap}") except Exception as e: print(f"An error occurred: {e}") finally: # Disconnect from the device if 'device' in locals() and device.is_connected('netconf'): device.disconnect(via='netconf') print(f"Disconnected from {device.name}.")
Debug
Known issues
breakingThe `configure()` method in `yang.connector.Netconf` is a placeholder and will raise an exception. It is not supported for NETCONF operations.
fix
Use the `edit_config()` method instead for sending configuration changes. The `request()` method can also be used for raw RPC requests.
affects: All versions
gotchaWhen using `request()` or other methods, if the NETCONF `rpc-reply` is in a wrong format, or if `message-id` is missing/mismatched, `ncclient` (which `yang.connector` wraps) may raise an `OperationError`.
fix
Ensure that the device's RPC replies conform to expected NETCONF standards and that message-ids are correctly handled if manually constructed. Review `ncclient` documentation for error handling.
affects: All versions
gotchaThe `request()` method in `Netconf` can raise a `TimeoutExpiredError` if the device does not send an `rpc-reply` within the specified timeout duration.
fix
Increase the `timeout` parameter when establishing the connection or when making the `request()` call, especially for large queries or slow devices. The default timeout is 30 seconds.
affects: All versions
Upgrade
Version history
26.5latest on PyPI · released May 28, 2026
Audit
Dependencies
ncclientrequiredyang.connector.Netconf wraps the ncclient library for NETCONF protocol implementation.
pyatsrequiredyang.connector is integrated into the pyATS framework and its Netconf class is based on pyATS BaseConnection.
Agent activity
44 hits · last 30 days
node
36
OpenAI (training)
1
Resources