Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

benparse

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benparse

Bencode parser

  • 1.0.2
  • PyPI
  • Socket score

Maintainers
1

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 and pickle
  • 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

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc