Simple bencode library for python
Project description
pybencode
Simple bencode library for python
Requirements
- python 3.6, 3.7, 3.8, 3.9
Installation
pip install cpyberry-pybencode
Usage
import pybencode
pybencode.encode(256) # return b"i256e"
pybencode.encode(b"neko") # return b"4:neko"
pybencode.encode([1, 2, 3]) # return b"li1ei2ei3ee"
pybencode.encode({1: b"kuro", 2: b"sakura"})
# return b"di1e4:kuroi2e6:sakurae"
Nested lists and dicts can also be encoded.
pybencode.encode([b"cat", 1024, [b"meow", b"woof"]])
# return b"l3:cati1024el4:meow4:woofee"
pybencode.encode({1: {b"yuki": b"ghost"}})
# return b"di1ed4:yuki5:ghostee"
Decode can do the opposite of the above.
Similarly, you can decode nested list and dict.
pybencode.decode(b"5:night") # return "night"
pybencode.decode(b"i128e") # return 128
python.decode(b"di1ed4:yuki5:ghostee")
# return {1: {b"yuki": b"ghost"}}
python.decode(b"l3:cati1024el4:meow4:woofee")
# return [b"cat", 1024, [b"meow", b"woof"]]
If you want to encode the string to bencode format, you need to encode it with any character code first.
For example
string = "coppelia"
pybencode.encode(string.encode("latin-1"))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for cpyberry_pybencode-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6417f2c5bc8b0f0d82caf55eef19a548ca893c9f3be2b0fc8661dd321d58073 |
|
MD5 | 3de9bd8af9f21d3ad987bc67485e7a0b |
|
BLAKE2b-256 | 3547db07f552b4a86092116bb92027a2127c30bcae0cde9efa5721d54a8a59c1 |