This package implements Bencodex serialization format which extends Bencoding.
This package's API follows the tradition of Python's pickle
and json
modules:
bencodex.dump(obj: bencodex.BValue, fileobj: typing.BinaryIO) -> None
bencodex.dumps(obj: bencodex.BValue) -> bytes
bencodex.load(fileobj: typing.BinaryIO) -> bencodex.BValue
bencodex.loads(encoded: bytes) -> bencodex.BValue
>>> from bencodex import dumps, loads
>>> dumps({'name': 'Jane Doe', 'age': 30, 'nationality': ['BR', 'US']})
b'du3:agei30eu4:nameu8:Jane Doeu11:nationalitylu2:BRu2:USee'
>>> loads(_)
{'age': 30, 'name': 'Jane Doe', 'nationality': ['BR', 'US']}
The package also provides a CLI program named show-bencodex
, which shows
the given Bencodex data file (or data from the stdin) in the debug-friendly
format:
$ show-bencodex bencodex.dat
$ cat bencodex.dat | show-bencodex
Distributed under GPLv3 or later.