Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/synodriver/sproto
pythonic sproto binding
https://github.com/synodriver/sproto
cython python python3 sproto
Last synced: 18 days ago
JSON representation
pythonic sproto binding
- Host: GitHub
- URL: https://github.com/synodriver/sproto
- Owner: synodriver
- License: bsd-3-clause
- Created: 2022-04-10T13:52:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-28T11:42:50.000Z (8 months ago)
- Last Synced: 2024-10-11T11:26:01.582Z (about 1 month ago)
- Topics: cython, python, python3, sproto
- Language: Python
- Homepage:
- Size: 1.15 MB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
- Changelog: changename.py
- License: LICENSE
Awesome Lists containing this project
README
✨ Pysproto ✨
Another Pythonic Sproto Python binding for sproto
Powered by cython, high performance, pythonic
[![pypi](https://img.shields.io/pypi/v/sproto.svg)](https://pypi.org/project/sproto/)
![python](https://img.shields.io/pypi/pyversions/sproto)
![implementation](https://img.shields.io/pypi/implementation/sproto)
![wheel](https://img.shields.io/pypi/wheel/sproto)
![license](https://img.shields.io/github/license/synodriver/sproto.svg)
![action](https://img.shields.io/github/workflow/status/synodriver/sproto/build%20wheel)### Usage
- install
```
pip install sproto
```- encode & decode
```python
from pysproto import parse, parse_ast, Sproto
ast = parse(""".package {
type 0 : integer
session 1 : integer
}""")
dump = parse_ast(ast)
proto = Sproto(dump)
tp = proto.querytype("package")
encoded = tp.encode({"type": 1, "session": 2})
print(tp.decode(encoded))
```- Public functions
```python
from typing import Union, Tuple, Optionalclass Sproto:
def dump(self)->None: ...
def protocol(self, tag_or_name: Union[int, str]) -> Tuple[Union[int, str], Optional["SprotoType"], Optional["SprotoType"]]: ...
def querytype(self, type_name) -> "SprotoType": ...
def sproto_protoresponse(self, intproto) -> int: ...class SprotoError(Exception): ...
class SprotoType:
@classmethod
def __init__(self, *args, **kwargs) -> None: ...
def decode(self, buffer: bytes) -> dict: ...
def encode(self, data: dict) -> bytes: ...
def encode_into(self, data: dict, buffer: bytearray) -> int: ...def pack(data: bytes) -> bytes: ...
def pack_into(data: bytes, buffer: bytearray) -> int: ...
def unpack(data: bytes) -> bytes: ...
def unpack_into(data: bytes, buffer: bytearray) -> int: ...
```
- ```xx_into``` functions accepts buffer protocol objects, which is zerocopy.