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
Release history Release notifications | RSS feed
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.3.tar.gz
(10.2 kB
view details)
Built Distribution
pproto_py-2.1.3-py3-none-any.whl
(13.5 kB
view details)
File details
Details for the file pproto-py-2.1.3.tar.gz
.
File metadata
- Download URL: pproto-py-2.1.3.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a279bc5e4cabd985edc436f2cf37886a423321dcb1df66aacca6a36ebbb678 |
|
MD5 | a443f15a550f39d9a6def5c1c93f81ac |
|
BLAKE2b-256 | 8a21f99110c8e683145f00fc715f3dad35f3aba0f922c453d15c78c9848947dc |
Provenance
The following attestation bundles were made for pproto-py-2.1.3.tar.gz
:
Publisher:
python-build-release.yml
on TochkaAI/pproto_py-2.0
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pproto_py-2.1.3.tar.gz
- Subject digest:
67a279bc5e4cabd985edc436f2cf37886a423321dcb1df66aacca6a36ebbb678
- Sigstore transparency entry: 146809107
- Sigstore integration time:
- Predicate type:
File details
Details for the file pproto_py-2.1.3-py3-none-any.whl
.
File metadata
- Download URL: pproto_py-2.1.3-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5411a3a3c87c14116e9fe457d40b6fabfcf5d447ab83ba283ed471f181525b70 |
|
MD5 | 911ad63fe4e91b93edcf23632ffcbdbe |
|
BLAKE2b-256 | d24fda11b4738a5cadfc916368556bd91b05e99d8de97785c0e3f780da31950f |
Provenance
The following attestation bundles were made for pproto_py-2.1.3-py3-none-any.whl
:
Publisher:
python-build-release.yml
on TochkaAI/pproto_py-2.0
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pproto_py-2.1.3-py3-none-any.whl
- Subject digest:
5411a3a3c87c14116e9fe457d40b6fabfcf5d447ab83ba283ed471f181525b70
- Sigstore transparency entry: 146809110
- Sigstore integration time:
- Predicate type: