pure-protobuf


Namepure-protobuf JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/eigenein/protobuf
SummaryProtocol Buffers using Python type annotations
upload_time2024-04-22 12:53:02
maintainerNone
docs_urlNone
authorPavel Perestoronin
requires_python<4.0.0,>=3.8.0
licenseMIT
keywords protobuf protocol-buffers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `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.8.0",
    "maintainer_email": null,
    "keywords": "protobuf, protocol-buffers",
    "author": "Pavel Perestoronin",
    "author_email": "eigenein@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/5f/b557dd76c8f1b3b2e3ce048a359bea56096fcef98fc1958c91daa0076d94/pure_protobuf-3.1.0.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.0",
    "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": "4c968cb7b2146a39d728835863cda6862ca6a382da4cf860cd957f57015a1102",
                "md5": "c72bfdef61e50c85d558e33bda79b76b",
                "sha256": "70a716e255f7e4f89efd9651b8d78f2afbef3c60e78d99aab61dc6555b7ee07e"
            },
            "downloads": -1,
            "filename": "pure_protobuf-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c72bfdef61e50c85d558e33bda79b76b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 27807,
            "upload_time": "2024-04-22T12:53:00",
            "upload_time_iso_8601": "2024-04-22T12:53:00.304368Z",
            "url": "https://files.pythonhosted.org/packages/4c/96/8cb7b2146a39d728835863cda6862ca6a382da4cf860cd957f57015a1102/pure_protobuf-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "995fb557dd76c8f1b3b2e3ce048a359bea56096fcef98fc1958c91daa0076d94",
                "md5": "73c3422874226d9d0c66740728dd6f8d",
                "sha256": "c0b60d630e529309b8ab3f94aec91acc478385ede02d115f7981b24c7151d89b"
            },
            "downloads": -1,
            "filename": "pure_protobuf-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "73c3422874226d9d0c66740728dd6f8d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 18198,
            "upload_time": "2024-04-22T12:53:02",
            "upload_time_iso_8601": "2024-04-22T12:53:02.151959Z",
            "url": "https://files.pythonhosted.org/packages/99/5f/b557dd76c8f1b3b2e3ce048a359bea56096fcef98fc1958c91daa0076d94/pure_protobuf-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 12:53:02",
    "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"
}
        
Elapsed time: 0.24451s