Skip to main content

Small library for encoding/decoding bencode data. Pyben Enables fast and easy encoding and decoding of bencoded data.

Project description

# Pyben v0.2.1

Small library for encoding/decoding bencode data. Pyben Enables fast and easy encoding and decoding of bencoded data.

![PyBen](./assets/pyben.png)

![GitHub repo size](https://img.shields.io/github/repo-size/alexpdev/pyben) ![GitHub contributors](https://img.shields.io/github/license/alexpdev/pyben) ![GitHub stars](https://img.shields.io/badge/rating-99-green)

## Prerequisites

  • Python3 installed and enabled

## Installing PyBen

To install PyBen, follow these steps:

Using pip:

`bash pip install pyben `

Using git:

`cmd git clone https://github.com/alexpdev/pyben.git `

## Using PyBen

The API is intentionally designed to mimic Python’s json module.

`python >>> fd = "path/to/file" >>> data = {"item1": ["item2", 3, [4], {5: "item6"}]} >>> encoded = pyben.dumps(data) >>> encoded b'd5:item1l5:item2i3eli4eedi5e5:item6eee' >>> decoded = pyben.loads(encoded) {'item1': ['item2', 3, [4], {5: 'item6'}]} `

One key difference is that the ‘load’ and ‘dump’ methods accept as arguments, string paths or path objects as well as open iobuffer.

For Example this:

`python >> with open("encoded.file", "wb") as fd: ... pyben.dump(data, fd) >> with open("encoded.file", "rb") as fd: ... decoded = pyben.load(fd) `

is the same as doing following.

`python >>> pyben.dump(data, "encoded.file") >>> decoded = pyben.load("encoded.file") `

The full API includes many other functions and classes as well. See docs for more full API.

## License

This project uses the following license: GNU LGPL v3

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

pyben-0.2.1.tar.gz (19.2 kB view hashes)

Uploaded Source

Built Distributions

pyben-0.2.1-py3.9.egg (8.2 kB view hashes)

Uploaded Source

pyben-0.2.1-py3-none-any.whl (11.2 kB view hashes)

Uploaded Python 3

Supported by

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