Skip to main content

Simple bencode library for python

Project description

pybencode

Simple bencode library for python

license

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


Download files

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

Source Distribution

cpyberry-pybencode-2.0.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cpyberry_pybencode-2.0.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file cpyberry-pybencode-2.0.1.tar.gz.

File metadata

  • Download URL: cpyberry-pybencode-2.0.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/2.1.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for cpyberry-pybencode-2.0.1.tar.gz
Algorithm Hash digest
SHA256 8069dcc1b44b845b1b56e2368421fb4a5ef0eaedb8cfcfd4d64a97e129d31b78
MD5 8956641b1a77fa373a50231009c97d17
BLAKE2b-256 d2ec612a854b2b8da8aef2c49e9cf39edd0386b442655a66af69d5e94535146a

See more details on using hashes here.

File details

Details for the file cpyberry_pybencode-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: cpyberry_pybencode-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/2.1.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for cpyberry_pybencode-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5abfeb09fa73a499f29482d0efc23af8d156c809d9ca4b341a159586a9e9be0d
MD5 c531fa554e9519b7ad7de0f0e0ec1506
BLAKE2b-256 b60741b6512fcff578862111d4146becd3f7f717f74b953d6c65f9c780362c26

See more details on using hashes here.

Supported by

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