Skip to main content

gNMI Python Client

Installation

Python 3

General Use

pip3 install gnmi-py

Development

git clone https://gitlab.aristanetworks.com/arista-northwest/gnmi-py.git
# installs pipenv and requirements
make init
pipenv shell

Python 2

Not supported :)

Usage

% gnmipy --help
usage: gnmipy [-h] [--version] [-c CONFIG] [-d] [-u USERNAME] [-p PASSWORD]
              [--encoding {json,bytes,proto,ascii,json-ietf}]
              [--prefix PREFIX] [--get-type {config,state,operational}]
              [--interval INTERVAL] [--timeout TIMEOUT]
              [--heartbeat HEARTBEAT] [--aggregate] [--suppress]
              [--mode {stream,once,poll}]
              [--submode {target-defined,on-change,sample}] [--once]
              [--qos QOS] [--use-alias]
              target {capabilities,get,subscribe} [paths [paths ...]]

positional arguments:
  target                gNMI gRPC server
  {capabilities,get,subscribe}
                        gNMI operation [capabilities, get, subscribe]
  paths

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -c CONFIG, --config CONFIG
                        Path to gNMI config file

  -d, --debug           enable gRPC debugging

  -u USERNAME, --username USERNAME
  -p PASSWORD, --password PASSWORD

Common options:
  --encoding {json,bytes,proto,ascii,json-ietf}
                        set encoding
  --prefix PREFIX       gRPC path prefix (default: <empty>)

Get options:
  --get-type {config,state,operational}

Subscribe options:
  --interval INTERVAL   sample interval in milliseconds (default: 10s)
  --timeout TIMEOUT     subscription duration in seconds (default: None)
  --heartbeat HEARTBEAT
                        heartbeat interval in milliseconds (default: None)
  --aggregate           allow aggregation
  --suppress            suppress redundant
  --mode {stream,once,poll}
                        Specify subscription mode
  --submode {target-defined,on-change,sample}
                        subscription sub-mode
  --once                End subscription after first sync_response. This is a
                        workaround for implementions that do not support
                        'once' subscription mode
  --qos QOS             DSCP value to be set on transmitted telemetry
  --use-alias           use aliases

Examples

Command-line

gnmipy -u admin veos1:6030 subscribe /interfaces

# using jq to filter results
gimpy -u admin veos1:6030 subscribe /system | \
  jq '{time: .time, path: (.prefix + .updates[].path), value: .updates[].value}'

API

from gnmi.structures import SubscribeOptions
from gnmi import capabilites, get, delete, replace, update, subscribe
from gnmi.exceptions import GrpcDeadlineExceeded

paths = ["/system"]
target = "veos:6030"

for notif in get(target, paths, auth=("admin", "")):
    prefix = notif.prefix
    for update in notif.updates:
        print(f"{prefix + update.path} = {update.get_value()}")
    for delete in notif.deletes:
        print(f"{prefix + delete} = DELETED")

for notif in subscribe(target, paths, auth=("admin", ""),
                       options=SubscribeOptions(mode="once")):
    prefix = notif.prefix
    for update in notif.updates:
        print(f"{prefix + update.path} = {update.get_value()}")
    for delete in notif.deletes:
        print(f"{prefix + delete} = __DELETED__")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gnmi-py-0.7.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gnmi_py-0.7.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file gnmi-py-0.7.1.tar.gz.

File metadata

  • Download URL: gnmi-py-0.7.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.7

File hashes

Hashes for gnmi-py-0.7.1.tar.gz
Algorithm Hash digest
SHA256 4ed4ea8f6c7a4a9c83215a6757a8f05c34288bf5d24a8e6c6ea51770cfe4ddb6
MD5 e31949a428fc423dfb112cc7e7b48b5c
BLAKE2b-256 e243d5c35c7749f1b3820f08424c92f5a6e174f6ae9f358e39d172d76f9c6b1a

See more details on using hashes here.

File details

Details for the file gnmi_py-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: gnmi_py-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.7

File hashes

Hashes for gnmi_py-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2475adf11656c3befd02b663db8138f54d6073362693deb88b428b69c16f505
MD5 786294bdcf30cf0e10225908d2251543
BLAKE2b-256 4ffc6ed4b50448285edcbf49fd76d154974877164d4c06ce87e52269d71b45ce

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.4

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

1 file

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.15

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page