Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

gNMI Protobuf

PyPI version Python Versions Code style: black

This project aims to be a base building block for gNMI projects written in Python.

The process of building pythonic libraries and applications using gRPC and Protocol Buffers have been fragmented. This often means that a developer needs to copy over proto files, generate Python source from these using protoc and use them in-tree for their project. There already exists several projects built in this fashion. While functional, these can be hard to reuse or maintain, often times resulting stale code and no versioning.

gnmi-proto builds on top of the improvement already done by betterproto and in turn by the grpclib library. Here, we make available, as versioned packages, code generated from gNMI protocol buffers.

The default implementation makes use of the betterproto protoc plugin to generate clean modern code. In addition, this also provides a gnmi.proto.legacy module exposing code generated by protoc using the the in-built Python generator.

Example Usage

Client

The following code expects a server at 127.0.0.1:9339 with the test configuration. Refer to gNMI Target Server section in CONTRIBUTING.md for information on how to set it up.

Using betterproto and grpclib

import gnmi.proto
import grpclib.client


async def main():
    channel = grpclib.client.Channel(host="127.0.0.1", port=9339, ssl=None)
    service = gnmi.proto.gNMIStub(
        channel, metadata={"username": "admin", "password": "secret"}
    )

    response = await service.capabilities()
    print(response.to_json(indent=2))

    response = await service.get(
        path=[gnmi.proto.Path(elem=[gnmi.proto.PathElem(name="interfaces")])],
    )
    print(response.to_json(indent=2))


if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Using vanilla grpc

import gnmi.proto.legacy
import grpc


def main():
    channel = grpc.insecure_channel("127.0.0.1:9339")
    metadata = [("username", "admin"), ("password", "secret")]
    service = gnmi.proto.legacy.gNMIStub(channel)

    response = service.Capabilities(gnmi.proto.legacy.CapabilityRequest())
    print(response)

    response = service.Get(
        gnmi.proto.legacy.GetRequest(
            path=[
                gnmi.proto.legacy.Path(
                    elem=[gnmi.proto.legacy.PathElem(name="interfaces")]
                )
            ],
        ),
        metadata=metadata,
    )
    print(response)


if __name__ == "__main__":
    main()

Metadata

Release files for gnmi-proto 0.1.0a4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gnmi-proto 0.1.0a4
File Size Uploaded
gnmi-proto-0.1.0a4.tar.gz 38.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gnmi-proto 0.1.0a4
File Interpreter ABI Platform
gnmi_proto-0.1.0a4-py3-none-any.whl Python 3 none any Details

Total release size: 81.8 kB

Release files / gnmi-proto-0.1.0a4.tar.gz

Download URL gnmi-proto-0.1.0a4.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
58bb4b93ac42df27e9d81a26ce5a02acafd83d96b4349a09d4f2c61124b95d2d
BLAKE2b-256 checksum
How to use checksums
1a9c71e6aba3824c3f28d124adf54bdb7a07e97adacca37b14a5be83b904ffc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure

Release files / gnmi_proto-0.1.0a4-py3-none-any.whl

Download URL gnmi_proto-0.1.0a4-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f51db92686bb10aeb686fb102718a29462e11bdfecc6dd341722dcacd71248d9
BLAKE2b-256 checksum
How to use checksums
9b7a6dc159f0c32208e02032e257cef7bedfedcb1373c8ef77348b66825934e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page