Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bencode_vug-0.1.0.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

bencode_vug-0.1.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

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

Hashes for bencode_vug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87fac563b4638b5c0c47a0646ca0812cded030aa45fb51987147927576c2b779
MD5 5a9ce4ea0eef0ca0703c53ba7f7ed6ae
BLAKE2b-256 fb737db725069ff40a2f4822112cdff9d4b525117fdc619dc48928ebbd8f6fc0

See more details on using hashes here.

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

Hashes for bencode_vug-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0426f71e7c8be30ae700a7e49985df0084816765d595c8c7de868c31c1848da
MD5 cfd6614a36fc5546e21e34fe5dbaad25
BLAKE2b-256 aa5b6d006b84733f4f8760eb073923709fff67821e74fb467b7b1d827da987f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page