A fast and correct bencode serialize/deserialize library


Keywords
bencode, bit-torrent, bittorrent, deserialize, p2p, serialize
License
MIT
Install
pip install bencode2==0.0.16

Documentation

A fast and correct bencode serialize/deserialize library

PyPI tests PyPI - Python Version Codecov branch

This library is compiled with cython on CPython, and pure python on PyPy.

install

pip install bencode2

basic usage

import bencode2


assert bencode2.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}

# If you want to decode dict with str keys:
# Note: this doesn't work with BitTorrent V2 torrent file.
assert bencode2.bdecode(b"d4:spaml1:a1:bee", str_key=True) == {"spam": [b"a", b"b"]}

assert bencode2.bencode({'hello': 'world'}) == b'd5:hello5:worlde'