# `pure-protobuf`
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/eigenein/protobuf/check.yml?label=checks&logo=github)](https://github.com/eigenein/protobuf/actions/workflows/check.yml)
[![Code coverage](https://codecov.io/gh/eigenein/protobuf/branch/master/graph/badge.svg?token=bJarwbLlY7)](https://codecov.io/gh/eigenein/protobuf)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pure-protobuf.svg)](https://pypistats.org/packages/pure-protobuf)
[![PyPI – Version](https://img.shields.io/pypi/v/pure-protobuf.svg)](https://pypi.org/project/pure-protobuf/#history)
[![PyPI – Python](https://img.shields.io/pypi/pyversions/pure-protobuf.svg?logo=python&logoColor=yellow)](https://pypi.org/project/pure-protobuf/#files)
[![License](https://img.shields.io/pypi/l/pure-protobuf.svg)](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/76/95/1ccc83c6e64d78da96899611043799b221918f3c30e3086dabc78dffc58a/pure_protobuf-3.1.3.tar.gz",
"platform": null,
"description": "# `pure-protobuf`\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/eigenein/protobuf/check.yml?label=checks&logo=github)](https://github.com/eigenein/protobuf/actions/workflows/check.yml)\n[![Code coverage](https://codecov.io/gh/eigenein/protobuf/branch/master/graph/badge.svg?token=bJarwbLlY7)](https://codecov.io/gh/eigenein/protobuf)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pure-protobuf.svg)](https://pypistats.org/packages/pure-protobuf)\n[![PyPI \u2013 Version](https://img.shields.io/pypi/v/pure-protobuf.svg)](https://pypi.org/project/pure-protobuf/#history)\n[![PyPI \u2013 Python](https://img.shields.io/pypi/pyversions/pure-protobuf.svg?logo=python&logoColor=yellow)](https://pypi.org/project/pure-protobuf/#files)\n[![License](https://img.shields.io/pypi/l/pure-protobuf.svg)](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.3",
"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": "494a6959c42ebef4fd42ee36e993f5789da3ba5ae64ac760541c227c782c125f",
"md5": "0b67f418df8d4075e6b9ab1c08616e7e",
"sha256": "d28e57d35f60c98695a4c1f809738143c41cc94e19f63603b38a04e64f6622a4"
},
"downloads": -1,
"filename": "pure_protobuf-3.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0b67f418df8d4075e6b9ab1c08616e7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.9.0",
"size": 28049,
"upload_time": "2024-10-15T20:47:06",
"upload_time_iso_8601": "2024-10-15T20:47:06.775261Z",
"url": "https://files.pythonhosted.org/packages/49/4a/6959c42ebef4fd42ee36e993f5789da3ba5ae64ac760541c227c782c125f/pure_protobuf-3.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76951ccc83c6e64d78da96899611043799b221918f3c30e3086dabc78dffc58a",
"md5": "af5cd709ae86544ffa932eb40c77d76c",
"sha256": "ae439e1920e9c0e6bf65bf892948085e021cb4a7dc3f2ec399b0ee735422f30d"
},
"downloads": -1,
"filename": "pure_protobuf-3.1.3.tar.gz",
"has_sig": false,
"md5_digest": "af5cd709ae86544ffa932eb40c77d76c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.9.0",
"size": 18341,
"upload_time": "2024-10-15T20:47:08",
"upload_time_iso_8601": "2024-10-15T20:47:08.174099Z",
"url": "https://files.pythonhosted.org/packages/76/95/1ccc83c6e64d78da96899611043799b221918f3c30e3086dabc78dffc58a/pure_protobuf-3.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 20:47:08",
"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"
}