Bencode parser
Project description
benparse
benparse is a bencode parser for Python 3. It is capable of reading and creating bencoded files such as torrents
Features
- Syntax is similar to built-in modules such as
json
andpickle
- Has an optional strict mode that will raise an error when it encounters non-fatal errors such as out-of-order dict keys or integers with leading zeros. This ensures that "round-tripping" bencoded data (loading bencoded data and then dumping it back to bencode) will never caused unexpected changes
- Able to change the character encoding used to encode/decode strings
- Fully typed
Usage
Complete usage documentation and examples are available here
# Load a bencoded file
with open('linux_distro.torrent', 'rb') as file:
torrent_dict = benparse.load(file)
# Make changes
torrent_dict[b'announce'] = b'http://mirror.example.org:6969/announce'
# Save a Python object as a bencoded file
with open('linux_distro.torrent', 'wb') as file:
benparse.dump(torrent_dict, file)
Requirements
- Python 3.6+
- Typing Extensions (only for Python versions less than 3.8)
Installation
Install from PyPI:
pip3 install benparse
Install from source:
git clone https://gitlab.com/adralioh/benparse.git
pip3 install ./benparse
Tests
Tests are run using the built-in unittest
module, and Coverage.py is used to measure code coverage
Run tests without measuring coverage:
python3 -m unittest discover tests
Run tests and measure coverage:
coverage run -m unittest discover tests
View the results:
coverage report
Generate a detailed report, outputted to ./htmlcov
:
coverage html
Building documentation
Sphinx is used to build documentation
Build requirements:
How to build:
cd docs
make html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
benparse-1.0.2.tar.gz
(11.2 kB
view details)
Built Distribution
benparse-1.0.2-py3-none-any.whl
(26.4 kB
view details)
File details
Details for the file benparse-1.0.2.tar.gz
.
File metadata
- Download URL: benparse-1.0.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7266f97d2e547e0b22aced9f8daedc7b082ea7c5cb9f7f7103bbabf8f252d2f5 |
|
MD5 | 9bb2d84b934e5c2fdc224c7e1ef63714 |
|
BLAKE2b-256 | 7b6fb69c87eee406cc65145ec0ad1da975b75318be597590479658bd6edfbe45 |
File details
Details for the file benparse-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: benparse-1.0.2-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43895f2c97ed7cd8ee8d8b949205d00eb0b795c020d44f93f833a16c8cfe0aad |
|
MD5 | 1154318f3725c2162880a8fa544c4cae |
|
BLAKE2b-256 | dee6b8fd6414b43924c523adf5cadbbb807e5c30af56e4ae3645ffbe9f5156ac |