Skip to main content

Tool to decode and encode .torrent files

Project description

bcoder

About


A Python package to handle bencoded values, a serialization format commonly used in .torrent files within the BitTorrent protocol.

Usage


There are 2 types of classes:

  • BDecoder - handle decoding of bencoded data to common Python types
  • BEncoder - handle encoding of common Python types to bytes type

Example of BDecoder usage:

from bcoder import BDecoder

decoder = BDecoder()

with open("file.torrent", "rb") as file:
    data = file.read()

decoded = decoder.decode(data)

Example of BEncoder usage:

from bcoder import BEncoder

encoder = BEncoder()

data = {
    b"announce-list": [
        [b"udp:..."],
        [b"udp:..."],
    ],
    b"info": {
        b"piece": b"xfsasf",
        b"piece length": 123,
    },
}

encoded = encoder.encode(data)

NOTE: BEncoder is spec-strict (BEP 3). Only bytes, int, list, and dict with bytes keys are accepted. Pass str through .encode("utf-8") yourself if you need to encode text.

Project details


Download files

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

Source Distribution

bcoder-2.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bcoder-2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file bcoder-2.0.tar.gz.

File metadata

  • Download URL: bcoder-2.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for bcoder-2.0.tar.gz
Algorithm Hash digest
SHA256 d1fe8b934a5b483cd991da624202b1825d69b009f4816c01a2e750f81dabc287
MD5 77cffa2f7efd2f710678d2138c49d1f4
BLAKE2b-256 3049589554069b6db78f6ac63b72f71701a4b9a3fc2afd7e885ed4856446e964

See more details on using hashes here.

File details

Details for the file bcoder-2.0-py3-none-any.whl.

File metadata

  • Download URL: bcoder-2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for bcoder-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8da611e2b6bdd392805b752402d24238090180cea2e4a66b67f28c8c58e4a22b
MD5 669f9edbe042ff18fe0ed4b1af525dd3
BLAKE2b-256 17a64c616cfe03647212013ef2124e01700a1958b0fbffd5597570415b97c6d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page