Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

An implementation of Bencode encoding in Python 3

Project description

An implementation of Bencode encoding in Python 3


import bencode
bencode.encode(OrderedDict((1, 2), (b'eggs', b'spam')))

Type mapping for encoding:

Bencode type Python type
Dictionary OrderedDict
List list
Byte string bytes
Integer int

Type mapping for decoding:

Python type Bencode type
dict Dictionary
list or tuple List
bytes Byte string
int Integer

If OrderedDict is passed instead of plain dict, the order will be preserved.

Compact peer encoding

This package also includes functions for ‘compact’ peer encoding as per bep 0023. Though not part of bencode itself, compact peer encoding is often used with it. Mainline DHT and most trackers encode peer information in this format.


from bencode.misc import pack_compact_peers_list, unpack_compact_peers_list

pack_compact_peers_list((('', 8080), ('', 9090)))

(('', 8080), ('', 9090))

Project details

Download files

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

Files for torrent-bencode, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size torrent-bencode-0.2.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page