This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

PyBencoder - your bencoded strings module

What is a Bencoded String?

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.

For more info on bencoding check out

It provides:
  • decoding of the different bencoded elements
  • encoding of the allowed types (byte strings, integers, lists, and dictionaries).


Requires Python 3 or later


python install

To run test suite:

python test


Import the module

from pybencoder.bencoder import PyBencoder


Encoding is very easy to do. Just pass as an argument your data to encode method. It will automagically call the right encoder for you.

ben = PyBencoder()

ben.encode(123) # encode an integer ‘i123e’ ben.encode(‘123’) # encode a string ‘3:123’ ben.encode([1, 2, 3]) # encode a list ‘li1ei2ei3ee’ ben.encode([1, 2, [ 4, 5]]) # encode a slightly more complex list ‘li1ei2eli4ei5eee’ ben.encode({ ‘one’: 1, ‘two’: 2, ‘three’: 3 }) # encode a dictionary ‘d5:threei3e3:twoi2e3:onei1ee’


Decoding is also easy to deal with. Just pass the bencoded string to decode method. Two mentions: - the first char of your bencoded string must be actually bencoded data, no garbage is allowed - at the end of the bencoded string it might be garbage data; after the extraction, you can also retrieve it

ben = PyBencoder()

ben.decode(‘i123e’) # decode an integer 123 ben.decode(‘i123esomeothergarbagedata’) # decode an integer with garbage data at the end ben.get_left() # gets what’s left -> ‘someothergarbagedata’

ben.decode(‘3:123somegarbage’) # decode a 3 chars string

ben.decode(‘li1ei2eli4ei5eee’) # decode a list [1, 2, [4, 5]]

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting