Skip to main content

A python package containing gnmi proto specification and generated python code.

Project description

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

Project details


Download files

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

Source Distribution

gnmi-proto-0.1.0a4.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

gnmi_proto-0.1.0a4-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file gnmi-proto-0.1.0a4.tar.gz.

File metadata

  • Download URL: gnmi-proto-0.1.0a4.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure

File hashes

Hashes for gnmi-proto-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 58bb4b93ac42df27e9d81a26ce5a02acafd83d96b4349a09d4f2c61124b95d2d
MD5 3c453974ee583a9a0e3e2c738065dec4
BLAKE2b-256 1a9c71e6aba3824c3f28d124adf54bdb7a07e97adacca37b14a5be83b904ffc3

See more details on using hashes here.

File details

Details for the file gnmi_proto-0.1.0a4-py3-none-any.whl.

File metadata

  • Download URL: gnmi_proto-0.1.0a4-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure

File hashes

Hashes for gnmi_proto-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 f51db92686bb10aeb686fb102718a29462e11bdfecc6dd341722dcacd71248d9
MD5 c2ae62ac724c1e2ea00b0f073949ce30
BLAKE2b-256 9b7a6dc159f0c32208e02032e257cef7bedfedcb1373c8ef77348b66825934e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page