pip install bencode-rs
import bencode_rs
assert bencode_rs.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}
assert bencode_rs.bencode({'hello': 'world'}) == b'd5:hello5:worlde'
there is no str/string in bencode, only bytes. so we decode bencode bytes to python bytes, since it may not be a utf8 string.
we encode python True
as int 1
and False
as int 0.