packed


License
Apache-2.0
Install
pip install packed==0.2.2

Documentation

packed

Codecov PyPI PyPI - Downloads Python Version

Installation

pip3 install packed

Usage

from packed import packable

@packable  # 1) register class
class EqualMatcher:
    def __init__(self, expected):
        self._expected = expected

    def match(self, actual):
        return actual == self._expected

    def __packed__(self):  # 2) pick fields
        return {"expected": self._expected}

client

from packed import pack

matcher = EqualMatcher("banana")
packed = pack(matcher)
# -> send «packed» over network

server

from packed import unpack

# <- recieve «packed» as binary
matcher = unpack(packed)
assert matcher.match("banana") is True