Install & Compatibility
Where this runs
tested against v0.8.15 · 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 0.861s · 56.6MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.8s · import 0.556s · 54MB
54MB installed
● package 54MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
gNMIclient
✓ from pygnmi.client import gNMIclient
This quickstart demonstrates how to connect to a gNMI target, retrieve its capabilities, and perform a 'Get' operation for a specific path. It includes placeholders for host, port, and credentials, defaulting to common local development values or environment variables. An example for 'Subscribe' is provided but commented out.
import os
from pygnmi.client import gNMIclient
# Environment variables for connection details or default values
GNMI_HOST = os.environ.get('GNMI_HOST', 'localhost')
GNMI_PORT = int(os.environ.get('GNMI_PORT', '50051'))
GNMI_USERNAME = os.environ.get('GNMI_USERNAME', 'admin')
GNMI_PASSWORD = os.environ.get('GNMI_PASSWORD', 'admin')
# Configure the gNMI target
target = {
'addr': f'{GNMI_HOST}:{GNMI_PORT}',
'username': GNMI_USERNAME,
'password': GNMI_PASSWORD,
'insecure': True, # Set to False for secure TLS connections and provide certificates
'encoding': 'JSON_IETF', # Or None to auto-detect based on device capabilities
}
try:
with gNMIclient(target=target) as c:
# Get device capabilities
capabilities = c.capabilities()
print("\n--- Device Capabilities ---")
print(capabilities)
# Example: Get system hostname (path may vary by device/OS)
# Using a common path, adjust as needed for your device
hostname_path = ['/system/state/hostname']
get_response = c.get(path=hostname_path, encoding='JSON_IETF')
print("\n--- Get Response (Hostname) ---")
print(get_response)
# Example: Subscribe to an operational state (uncomment to run)
# subscription_paths = [
# ('/interfaces/interface[name=eth0]/state/oper-status', True)
# ]
# print("\n--- Subscribe (Streaming) ---")
# for update in c.subscribe2(path_tuples=subscription_paths, subscribe_mode='STREAM', encoding='JSON_IETF'):
# print(update)
# # Add logic to break from loop after a few updates or a timeout
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure the gNMI server is running and accessible with correct credentials.")
Errors
Common errors & fixes
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAUTHENTICATED details = "Authentication failed"
Incorrect username/password, or missing authentication details in the gNMI client configuration.
fixVerify the `username` and `password` in the `target` dictionary. Ensure these credentials match what the gNMI server expects.
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "Connect Failed"
The gNMI server is unreachable, incorrect host/port in the target address, or a firewall is blocking the connection.
fixCheck the `addr` in the `target` dictionary for correct host and port. Ensure the gNMI server is running and network connectivity exists between the client and server.
TypeError: 'NoneType' object is not subscriptable
Attempting to access elements of a gNMI response that is `None` or empty, often due to an invalid gNMI path or the requested data not existing on the device.
fixVerify the gNMI `path` is correct and exists on the target device. Add checks for `None` or empty responses (e.g., `if response and response.notification:`) before processing data.
TypeError: subscribe() got an unexpected keyword argument 'qos'
Using arguments (like `qos`) that are only supported by the `subscribe2()` method with the older `subscribe()` method, or attempting to use a feature not supported by the target device.
fixMigrate from `subscribe()` to `subscribe2()` for all telemetry subscriptions, as `subscribe2()` is the recommended and actively developed method. Ensure all arguments are appropriate for `subscribe2()` and supported by your gNMI target.
Upgrade
Version history
0.8.15latest on PyPI · released Mar 10, 2025
Audit
Dependencies
grpciorequiredRequired for gRPC communication with gNMI targets.
protobufrequiredUnderlying data serialization for gRPC messages.