bencode.py
Simple bencode parser (for Python 2, Python 3 and PyPy)
What it is and what it does
bencode.py is a parser for the bencode format, the binary encoding scheme used in BitTorrent and related peer-to-peer protocols. It provides both encoding (Python objects to bencode strings) and decoding (bencode strings back to Python objects) with configurable handling of string encoding, dictionary ordering, and nesting depth limits.
The package offers a simple functional API (encode/decode) for quick use, plus a class-based API (Bencode, BencodeEncoder, BencodeDecoder) for fine-grained control over encoding behavior, fallback strategies, and file I/O. It has no runtime dependencies and works across Python 2, Python 3, and PyPy, making it portable for legacy and modern codebases alike.
Use it for:
- Parse and extract metadata from .torrent files or BitTorrent protocol messages
- Serialize Python data structures into bencode format for peer-to-peer applications
- Build tools that interact with BitTorrent clients or DHT (Distributed Hash Table) networks
- Handle bencode-encoded configuration or data interchange in legacy systems
- Decode bencode strings with custom encoding fallback strategies for mixed or corrupted data
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Encodes and decodes bencode format, the binary encoding used in BitTorrent and related protocols, supporting Python 2, Python 3, and PyPy.
Yes, if you need bencode support. Low install friction, no dependencies, active maintenance, and no known vulnerabilities make it a straightforward choice. The main caveat is the unclear license status—verify BitTorrent Open Source License compatibility with your project's constraints before committing to production use.
Install
bencode-py on PyPI
pip
pip install bencode-pyuv
uv add bencode-pypoetry
poetry add bencode-pyInstalling bencode.py
Before you install
Low install friction with no runtime dependencies. Actively maintained as of 2026-07-07 with recent release history.
License in practice
Licensed under BitTorrent Open Source License (license_treatment: unclear). The license status is not mapped to a standard SPDX identifier, so review the raw license terms before use in proprietary or restricted contexts.
Quickstart
pip install bencode.py
import bencodepy
# Encode
bencodepy.encode({'title': 'Example'})
# b'd5:title7:Examplee'
# Decode
bencodepy.decode('d5:title7:Examplee')
# {b'title': b'Example'}
Verify before relying
- Whether BitTorrent Open Source License permits use in closed-source or commercial projects without restrictions
- Specific Python version support (requires_python field is unspecified in metadata)
Package facts
| License | BitTorrent Open Source License (unclear) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 38 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 203,862/month — #9,619 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bencode_py-4.1.0-py3-none-any.whl
Keywords: bittorrent, bencode, bdecode
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
java-manifestEncode and decode Java's META-INF/MANIFEST.MF…
unclear · top 15,000 on PyPI
pylzsspylzss decodes and encodes data compressed with…
copyleft · top 15,000 on PyPI
libtorrentPython bindings for libtorrent-rasterbar,…
permissive · top 15,000 on PyPI
asn1Encodes and decodes ASN.1 data structures using…
permissive · top 5,000 on PyPI
py-multibaseEncodes and decodes data using the Multibase…
permissive · top 15,000 on PyPI
ecojiEncodes and decodes binary data as sequences of…
permissive · top 15,000 on PyPI
x690Encodes and decodes data using the X.690 BER…
permissive · top 15,000 on PyPI
pynvvideocodecPyNvVideoCodec provides hardware-accelerated…
permissive · top 15,000 on PyPI
pyasn1Pyasn1 encodes and decodes ASN.1 data…
permissive · top 100 on PyPI
pylsqpackpylsqpack provides Python Decoder and Encoder…
permissive · top 5,000 on PyPI