# `pure-protobuf`
[](https://github.com/eigenein/protobuf/actions/workflows/check.yml)
[](https://codecov.io/gh/eigenein/protobuf)
[](https://pypistats.org/packages/pure-protobuf)
[](https://pypi.org/project/pure-protobuf/#history)
[](https://pypi.org/project/pure-protobuf/#files)
[](https://github.com/eigenein/protobuf/blob/master/LICENSE)
<small><strong>Wow! Such annotated! Very buffers!</strong></small>
## Documentation
<a href="https://eigenein.github.io/protobuf/">
<img alt="Documentation" height="30em" src="https://img.shields.io/github/actions/workflow/status/eigenein/protobuf/docs.yml?label=documentation&logo=github">
</a>
## Quick examples
### `.proto` definition
It's not needed for `pure-protobuf`, but for the sake of an example, let's consider the following definition:
```protobuf
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](https://docs.python.org/3/library/dataclasses.html)
```python title="dataclass_example.py"
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`](https://docs.pydantic.dev/)
```python title="pydantic_example.py"
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/eigenein/protobuf",
"name": "pure-protobuf",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.9.0",
"maintainer_email": null,
"keywords": "protobuf, protocol-buffers",
"author": "Pavel Perestoronin",
"author_email": "eigenein@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/11/49/2bbc64c052c63a63ba5c9af561734e8e5c6e440b1ce325617fca4b5ecea6/pure_protobuf-3.1.5.tar.gz",
"platform": null,
"description": "# `pure-protobuf`\n\n[](https://github.com/eigenein/protobuf/actions/workflows/check.yml)\n[](https://codecov.io/gh/eigenein/protobuf)\n[](https://pypistats.org/packages/pure-protobuf)\n[](https://pypi.org/project/pure-protobuf/#history)\n[](https://pypi.org/project/pure-protobuf/#files)\n[](https://github.com/eigenein/protobuf/blob/master/LICENSE)\n\n<small><strong>Wow! Such annotated! Very buffers!</strong></small>\n\n## Documentation\n\n<a href=\"https://eigenein.github.io/protobuf/\">\n <img alt=\"Documentation\" height=\"30em\" src=\"https://img.shields.io/github/actions/workflow/status/eigenein/protobuf/docs.yml?label=documentation&logo=github\">\n</a>\n\n## Quick examples\n\n### `.proto` definition\n\nIt's not needed for `pure-protobuf`, but for the sake of an example, let's consider the following definition:\n\n```protobuf\nsyntax = \"proto3\";\n\nmessage SearchRequest {\n string query = 1;\n int32 page_number = 2;\n int32 result_per_page = 3;\n}\n```\n\nAnd here's the same via `pure-protobuf`:\n\n### With [dataclasses](https://docs.python.org/3/library/dataclasses.html)\n\n```python title=\"dataclass_example.py\"\nfrom dataclasses import dataclass\nfrom io import BytesIO\n\nfrom pure_protobuf.annotations import Field\nfrom pure_protobuf.message import BaseMessage\nfrom typing_extensions import Annotated\n\n\n@dataclass\nclass SearchRequest(BaseMessage):\n query: Annotated[str, Field(1)] = \"\"\n page_number: Annotated[int, Field(2)] = 0\n result_per_page: Annotated[int, Field(3)] = 0\n\n\nrequest = SearchRequest(query=\"hello\", page_number=1, result_per_page=10)\nbuffer = bytes(request)\nassert buffer == b\"\\x0A\\x05hello\\x10\\x01\\x18\\x0A\"\nassert SearchRequest.read_from(BytesIO(buffer)) == request\n```\n\n### With [`pydantic`](https://docs.pydantic.dev/)\n\n```python title=\"pydantic_example.py\"\nfrom io import BytesIO\n\nfrom pure_protobuf.annotations import Field\nfrom pure_protobuf.message import BaseMessage\nfrom pydantic import BaseModel\nfrom typing_extensions import Annotated\n\n\nclass SearchRequest(BaseMessage, BaseModel):\n query: Annotated[str, Field(1)] = \"\"\n page_number: Annotated[int, Field(2)] = 0\n result_per_page: Annotated[int, Field(3)] = 0\n\n\nrequest = SearchRequest(query=\"hello\", page_number=1, result_per_page=10)\nbuffer = bytes(request)\nassert buffer == b\"\\x0A\\x05hello\\x10\\x01\\x18\\x0A\"\nassert SearchRequest.read_from(BytesIO(buffer)) == request\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Protocol Buffers using Python type annotations",
"version": "3.1.5",
"project_urls": {
"Changelog": "https://github.com/eigenein/protobuf/blob/master/CHANGELOG.md",
"Homepage": "https://github.com/eigenein/protobuf",
"Issues": "https://github.com/eigenein/protobuf/issues",
"Repository": "https://github.com/eigenein/protobuf"
},
"split_keywords": [
"protobuf",
" protocol-buffers"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f4efcad3d78e86f75a56e64d238d73393d37cf5c874d31819735ae2dba35e4b3",
"md5": "d132241a88c5de428e294aec11361ac3",
"sha256": "a7e9f57522d6e6f04f683cb4cded4eecfb18a1912b5a4aaed1745c1265f5620a"
},
"downloads": -1,
"filename": "pure_protobuf-3.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d132241a88c5de428e294aec11361ac3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.9.0",
"size": 28122,
"upload_time": "2025-09-02T21:45:15",
"upload_time_iso_8601": "2025-09-02T21:45:15.605131Z",
"url": "https://files.pythonhosted.org/packages/f4/ef/cad3d78e86f75a56e64d238d73393d37cf5c874d31819735ae2dba35e4b3/pure_protobuf-3.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "11492bbc64c052c63a63ba5c9af561734e8e5c6e440b1ce325617fca4b5ecea6",
"md5": "25019b33ffad672962ddc76518199407",
"sha256": "2e33554cbe2e664a099546f6fd1d6130e409df2d7a8c68b6ee9ce56f4c5d6dfc"
},
"downloads": -1,
"filename": "pure_protobuf-3.1.5.tar.gz",
"has_sig": false,
"md5_digest": "25019b33ffad672962ddc76518199407",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.9.0",
"size": 17351,
"upload_time": "2025-09-02T21:45:16",
"upload_time_iso_8601": "2025-09-02T21:45:16.493168Z",
"url": "https://files.pythonhosted.org/packages/11/49/2bbc64c052c63a63ba5c9af561734e8e5c6e440b1ce325617fca4b5ecea6/pure_protobuf-3.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-02 21:45:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "eigenein",
"github_project": "protobuf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pure-protobuf"
}