Proto Plus for Python

1.27.2 · active · verified Sat Mar 28

A Python library that provides a beautiful, Pythonic interface for working with protocol buffers. Current version: 1.27.2. Maintained with regular updates.

Warnings

Install

Imports

Quickstart

A simple example demonstrating how to define and use protocol buffer messages with Proto Plus.

import proto

class Composer(proto.Message):
    given_name = proto.Field(proto.STRING, number=1)
    family_name = proto.Field(proto.STRING, number=2)

class Song(proto.Message):
    composer = proto.Field(Composer, number=1)
    title = proto.Field(proto.STRING, number=2)
    lyrics = proto.Field(proto.STRING, number=3)
    year = proto.Field(proto.INT32, number=4)

song = Song(
    composer={'given_name': 'Johann', 'family_name': 'Pachelbel'},
    title='Canon in D',
    year=1680,
)
print(song.composer.family_name)  # Output: Pachelbel
print(song.title)  # Output: Canon in D

view raw JSON →