Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexpdev/pyben
bencode library and python implementation, with identical API as the python's json module.
https://github.com/alexpdev/pyben
bencode encoder encoder-decoder encoding library python
Last synced: 24 days ago
JSON representation
bencode library and python implementation, with identical API as the python's json module.
- Host: GitHub
- URL: https://github.com/alexpdev/pyben
- Owner: alexpdev
- License: apache-2.0
- Created: 2021-09-11T01:21:02.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-22T03:36:58.000Z (over 1 year ago)
- Last Synced: 2024-10-15T20:22:33.227Z (about 1 month ago)
- Topics: bencode, encoder, encoder-decoder, encoding, library, python
- Language: Python
- Homepage:
- Size: 1.18 MB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pyben v0.3.3
Small library for encoding/decoding bencode data.
Supports Unicode pathnames as of PyBen 3.0.
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?style=flat-square)
![GitHub contributors](https://img.shields.io/github/license/alexpdev/pyben)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pyben?color=%23CC3919&label=PyPi%20Downloads&logo=PyPi&logoColor=cyan&style=flat-square)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/af86338dcf0a4a899228df470d20e894)](https://www.codacy.com/gh/alexpdev/pyben/dashboard?utm_source=github.com&utm_medium=referral&utm_content=alexpdev/pyben&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/af86338dcf0a4a899228df470d20e894)](https://www.codacy.com/gh/alexpdev/pyben/dashboard?utm_source=github.com&utm_medium=referral&utm_content=alexpdev/pyben&utm_campaign=Badge_Coverage)
[![codecov](https://codecov.io/gh/alexpdev/pyben/branch/master/graph/badge.svg?token=N6TCUUQ6CJ)](https://codecov.io/gh/alexpdev/pyben)## Prerequisites
Python v3.6+
## Installing PyBen
To install PyBen, follow these steps:
Using pip:
`pip install pyben`
Using git:
`git clone https://github.com/alexpdev/pyben.git`
## Using PyBen
The API is intentionally designed to mimic Python's json and pickle modules.
>>> import os
>>> import pyben
>>> file_path = "path/to/encoded.file"
>>> data = {"item1": ["item2", 3, [4], {5: "item6"}]}
>>> encoded = pyben.dumps(data)
>>> encoded
... b'd5:item1l5:item2i3eli4eedi5e5:item6eee'
>>> decoded = pyben.loads(encoded)
>>> decoded
... {'item1': ['item2', 3, [4], {5: 'item6'}]}
>>> decoded == data
... TrueOne key difference is that the 'load' and 'dump' methods accept as arguments,
string paths or path-like objects as well as an open BytesIO object.For Example this:
>>> with open(file_path, "wb") as fd:
>>> pyben.dump(decoded, fd)
>>> os.path.exists(file_path)
... True
>>> with open(file_path, "rb") as fd:
>>> decoded_file = pyben.load(fd)
>>> decoded_file == decoded == data
... Trueis the same as doing following.
>>> pyben.dump(data, file_path)
>>> os.path.exists(file_path)
... True
>>> decoded_file = pyben.load(file_path)
>>> decoded_file == decoded == data
... TrueThe full API includes many other functions and classes as well.
See docs for more full API.## License
This project uses the following license: Apache 2.0
## Documentation
Github Pages: https://alexpdev.github.io/pyben