A package to encode and decode bencoded data
Project description
Bencode
A module that mimics the json standard lib module interface for
Bencode
Installation
Simply clone the repository and then run the following on the root dir of the repo.
python3 -m build && python3 -m pip install dist/bencode-0.0.1-py3-none-any.whl
Usage
Reading bencoded data
Both load and loads functions will decode bencoded data.
import bencode
decoded_dic = bencode.loads(encoded_data)
# deserializing bencoded data from a file
with open("bencoded_file.torrent", "rb") as fp:
decoded_dic = bencode.load(fp)
Encoding data
Pragmatically, only dictionaries are encoded in real life applications of this encoding format, but any other supported types can be singularly encoded.
import bencode
peers_dic = {b'peers': [
{b'127.0.0.1': b'29123'},
{b'127.0.0.1': b'6432'}
]}
# b'd5:peersld9:127.0.0.15:29123ed9:127.0.0.14:6432eee'
bencoded_peers = bencode.dumps(peers_dic)
# serialize an object as a bencoded stream to a file:
with open("my_bencoded_file.torrent", "rb") as fp:
bencode.dump(peers_dic, fp)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bencode_vug-0.1.0.tar.gz.
File metadata
- Download URL: bencode_vug-0.1.0.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87fac563b4638b5c0c47a0646ca0812cded030aa45fb51987147927576c2b779
|
|
| MD5 |
5a9ce4ea0eef0ca0703c53ba7f7ed6ae
|
|
| BLAKE2b-256 |
fb737db725069ff40a2f4822112cdff9d4b525117fdc619dc48928ebbd8f6fc0
|
File details
Details for the file bencode_vug-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bencode_vug-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0426f71e7c8be30ae700a7e49985df0084816765d595c8c7de868c31c1848da
|
|
| MD5 |
cfd6614a36fc5546e21e34fe5dbaad25
|
|
| BLAKE2b-256 |
aa5b6d006b84733f4f8760eb073923709fff67821e74fb467b7b1d827da987f3
|