Skip to main content

pproto_py is Python implementation of "Point Of View" communication protocol

Project description

pproto-py 2.0

Example Client

import asyncio
from uuid import UUID
from pproto_py import Client, BaseContent, to_model, BasePprotoErrorContent
from uuid import uuid4, UUID


class testMy(BaseContent):
    value1: int
    value2: str

    async def answer(self, data) -> None:
        print(data)


class testMy2(BaseContent):
    value1: int
    value2: UUID

    @to_model(testMy)
    async def answer(self, data: testMy) -> None:
        print(data.model_dump_json())

    @to_model(BasePprotoErrorContent)
    async def error(self, data: BasePprotoErrorContent) -> None:
        print(data.model_dump_json())


async def main():
    client = await Client.create_connect(host="127.0.0.1", port=8888)

    test2 = testMy2(value1=10, value2=uuid4())
    test_id2 = await test2.send(client, command="114949cb-2b6a-48f4-a5a4-15a682b2f45a")
    print("dsa")


if __name__ == "__main__":
    asyncio.run(main())

Example Server

import asyncio
from typing import Dict
from uuid import UUID
from pproto_py import Pproto
from pproto_py import BaseContent, BaseMessage, Status, BasePprotoErrorContent


class CommonException(Exception):
    def __init__(self, error: str) -> None:
        super().__init__()
        self.error = error


class testMy(BaseContent):
    value1: int
    value2: str


server = Pproto()


@server.exception_handler(CommonException)
async def common_exception(message: Dict[str,str], exc: CommonException):
    print(exc.error)
    message_error = BaseMessage(command=message.command)
    message_error.flags.exec_status.value = Status.ERROR.value
    message_error.content = BasePprotoErrorContent(error=exc.error)
    return message_error


@server.command(id=UUID("114949cb-2b6a-48f4-a5a4-15a682b2f45a"),
                response_model=testMy)
async def example1(content):
    # raise CommonException(error="Фигня какая-то")
    dsa = testMy(value1=1,value2="dsa")
    return dsa


async def main():
    await server.run()


if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pproto_py-2.1.6a0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pproto_py-2.1.6a0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file pproto_py-2.1.6a0.tar.gz.

File metadata

  • Download URL: pproto_py-2.1.6a0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pproto_py-2.1.6a0.tar.gz
Algorithm Hash digest
SHA256 a696d7c39170fac348d989325db31d5a99ecb56fcb331eb01e897115693b70ad
MD5 02bb2ba20a9ba68bcc94196770b7a740
BLAKE2b-256 44ee93e37a7eaeac48a151793619152a60a3d019c656cd70d5f0b7364c53caf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pproto_py-2.1.6a0.tar.gz:

Publisher: python-build-release.yml on TochkaAI/pproto_py-2.0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pproto_py-2.1.6a0-py3-none-any.whl.

File metadata

  • Download URL: pproto_py-2.1.6a0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pproto_py-2.1.6a0-py3-none-any.whl
Algorithm Hash digest
SHA256 2882e8bf35b03d175df61d3b0e41a803103ad13e02d6c2ec604174e0eda540b4
MD5 1d0eb50ab51fac58c31094fa7ceecb71
BLAKE2b-256 18fc4e74ede631aae795134dbee792709cd8b40cab68df4a50b546a542f206f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pproto_py-2.1.6a0-py3-none-any.whl:

Publisher: python-build-release.yml on TochkaAI/pproto_py-2.0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page