Skip to content

soareseng/bencoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bencoder

Python Version Tests License

Bencoder is a lightweight, type-safe Python module for Bencode encoding and decoding, designed for use in BitTorrent clients.

It fully supports:

  • Integers (int)
  • Strings (str -> bytes)
  • Bytes (bytes)
  • Lists (list)
  • Dictionaries (dict)
  • Nested structures
  • Explicit errors for invalid input
  • Full unit test coverage with pytest

Installation

git clone https://github.com/soareseng/bencoder.git
cd bencoder

python -m venv venv

# Linux / macOS
source venv/bin/activate

# Windows (PowerShell)
venv\Scripts\Activate.ps1

# Windows (cmd)
venv\Scripts\activate.bat

pip install -r requirements.txt

Basic Usage

from src.bencoder import Encoder, Decoder

encode = Encoder().encode

# Encode values
data = {"name": "Alice", "age": 30, "files": ["a.txt", "b.txt"]}
encoded = encode(data)
print(encoded)
# Output: b'd3:agei30e5:filesl5:a.txt5:b.txte4:name5:Alicee'

# Decode
decoded = Decoder(encoded).decode()
print(decoded)
# Output: {b'age': 30, b'files': [b'a.txt', b'b.txt'], b'name': b'Alice'}

Note: all strings are converted to bytes after decoding, in accordance with the Bencode specification.

Contributing

Pull requests are welcome! Enhancements such as performance optimizations, streaming decode, or additional tests are highly encouraged.

  • Open issues for bugs or feature requests
  • Fork the repo, implement, and submit a PR

License

MIT License © [Soares W. / soareseng]

About

A Python implementation of a bencoder for encoding and decoding data in the bencode format used by BitTorrent.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages