skillfed

bencode.py

Simple bencode parser (for Python 2, Python 3 and PyPy)

bencode-py v4.1.0 203.9K downloads/30d#9,619 on PyPI57
License unclear BitTorrent Open Source License Active released

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-py

uv

uv add bencode-py

poetry

poetry add bencode-py

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: Other/Proprietary LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 3Programming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries

Tags

bencode encoder decoderbittorrent bencode parserbencode python libraryencode decode bencodetorrent metadata parsingbencode serialization
bittorrentserialization

More Libraries packages