Skip to main content

Bendercoder

Build Status Coverage Status

Library for encoding and decoding bencode data.

Table of content

Introduction

Bencode (pronounced like B-encode) is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data. It supports four different types of values:

  • byte strings,
  • integers,
  • lists,
  • dictionaries (associative arrays).

Bencoding is most commonly used in torrent files. These metadata files are simply bencoded dictionaries.

Description from wikipedia.

Installing

pip install bendercoder

Usage

For decoding and encoding the integer number 10.

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'i10e')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the string foo.

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'3:foo')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the list [1, 2, 3, 'bar']

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'li1ei2ei3e3:bare')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the dictionary {'test': 'foo', 'bar': 2}

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'd4:test3:foo3:bari2ee')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

Release files for bendercoder 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bendercoder 1.2.1
File Size Uploaded
bendercoder-1.2.1.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bendercoder 1.2.1
File Interpreter ABI Platform
bendercoder-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / bendercoder-1.2.1.tar.gz

Download URL bendercoder-1.2.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b85a8a56732a19853e277640cc752502c70c46fc6635580fc35cf32ae35807c3
BLAKE2b-256 checksum
How to use checksums
ea3171b06381a9aead39a32878cae0fc6ce7cc7e7fdf276231487687afebf2cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0b3

Release files / bendercoder-1.2.1-py3-none-any.whl

Download URL bendercoder-1.2.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04ceb77c53d834634cd4266459e93603af0e14b6e5c23c433ec6439f9725d34d
BLAKE2b-256 checksum
How to use checksums
526e272e0a306fb5c2ab41e98d49958a411cf2caec16361fc33e63c94c1c08ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0b3

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page