• Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python implementation of Protocol Buffers with dataclass-based schemaʼs

pure-protobuf

GitHub Workflow Status Code coverage PyPI - Downloads PyPI – Version PyPI – Python License

Wow! Such annotated! Very buffers!

⚠️ Note
This README describes the upcoming major version update. For 2.x please refer to: https://github.com/eigenein/protobuf/tree/2.2.3

Documentation

Documentation

Quick examples

.proto definition

It's not needed for pure-protobuf, but for the sake of an example, let's consider the following definition:

syntax = "proto3";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

And here's the same via pure-protobuf:

With dataclasses

from dataclasses import dataclass
from io import BytesIO

from pure_protobuf.annotations import Field
from pure_protobuf.message import BaseMessage
from typing_extensions import Annotated


@dataclass
class SearchRequest(BaseMessage):
    query: Annotated[str, Field(1)] = ""
    page_number: Annotated[int, Field(2)] = 0
    result_per_page: Annotated[int, Field(3)] = 0


request = SearchRequest(query="hello", page_number=1, result_per_page=10)
buffer = bytes(request)
assert buffer == b"\x0A\x05hello\x10\x01\x18\x0A"
assert SearchRequest.read_from(BytesIO(buffer)) == request

With pydantic

from io import BytesIO

from pure_protobuf.annotations import Field
from pure_protobuf.message import BaseMessage
from pydantic import BaseModel
from typing_extensions import Annotated


class SearchRequest(BaseMessage, BaseModel):
    query: Annotated[str, Field(1)] = ""
    page_number: Annotated[int, Field(2)] = 0
    result_per_page: Annotated[int, Field(3)] = 0


request = SearchRequest(query="hello", page_number=1, result_per_page=10)
buffer = bytes(request)
assert buffer == b"\x0A\x05hello\x10\x01\x18\x0A"
assert SearchRequest.read_from(BytesIO(buffer)) == request

More Repositories

1

my-iot-rs

Yet another home automation (alpha)
SCSS
32
star
2

rc-car

DIY RC car controlled by Android app via Bluetooth
Kotlin
12
star
3

bestmobabot

«Хроники Хаоса» – бот для VK.com
Python
10
star
4

python-avm2

Adobe Flash SWF file parser and AVM2 virtual machine implementation in pure Python
Python
9
star
5

replay-reader

World of Tanks replay parser ported to C#
C#
8
star
6

joypad-android

Joypad View for Android
Java
8
star
7

ntc-one-wire

NTC thermistor to 1-Wire converter on Arduino Nano
C
7
star
8

skyninja

Sky Ninja (/skˈaɪ ˈnɪn.dʒə/) is a Skype history exporting application
C#
6
star
9

typst-templates

Templates for Typst
Typst
6
star
10

sqlitemap

Dictionary interface to an SQLite database
Python
6
star
11

mrktpltsbot

Marktplaats search notifications in Telegram (Unofficial)
Rust
6
star
12

ns-bot

Unofficial journey planner for Nederlandse Spoorwegen trains.
Python
5
star
13

wotbreplay-parser

World of Tanks Blitz replay parser
Rust
5
star
14

skype-historian

Lets you easily backup your Skype chats (unsupported)
HTML
4
star
15

python-as3

Adobe ActionScript 3 interpreter in Python (incomplete)
Python
4
star
16

nest-restream

Helper scripts to restream Google Nest cams to YouTube
Python
4
star
17

replay-toolkit

World of Tanks Replay Toolkit
Python
4
star
18

rusty-home

Hobby set of «smart home» microservices
Rust
4
star
19

led-strip

IoT LED strip controller
C++
3
star
20

cloudy

Cloudy Message Passing Library
C#
3
star
21

evernote-markdown

Evernote ENEX to Markdown converter
Python
3
star
22

kv-derive

Derive struct conversions from and to key-value vectors
Rust
3
star
23

blitz-dashboard

World of Tanks Blitz Dashboard Web App
Rust
3
star
24

wot-toolkit

Toolkit to collect World of Tanks wins statistics via API
Python
2
star
25

smart-home

Building a smart home Android app
Kotlin
2
star
26

bpci

Binomial proportion confidence intervals
Rust
2
star
27

robot

Building a remote-controlled car with Raspberry Pi Pico
Python
2
star
28

wotbreplay-inspector

World of Tanks Blitz replay inspector
Rust
2
star
29

aiotg

Telegram Bot API wrapper for aiohttp.
Python
2
star
30

livolo-floor-controller

C++
1
star
31

att

Themes for Telegram for Android
Python
1
star
32

epicwar

🏆 Epic War VK.com bot
Python
1
star
33

loggerbot

Simple Telegram bot that logs chat messages.
Python
1
star
34

rusty-tank

Attempt to build a recommender system for World of Tanks
Rust
1
star
35

contact-list

Python
1
star
36

rust-hyperopt

Tree-of-Parzen-estimators hyperparameter optimization
Rust
1
star
37

lamborduino-android

Remote control for my DIY RC-robot.
Java
1
star