https://github.com/synodriver/fast-bencode
fast bencode for python, based on cython
https://github.com/synodriver/fast-bencode
bencode cython
Last synced: 10 months ago
JSON representation
fast bencode for python, based on cython
- Host: GitHub
- URL: https://github.com/synodriver/fast-bencode
- Owner: synodriver
- Created: 2021-05-28T18:41:42.000Z (over 4 years ago)
- Default Branch: sds
- Last Pushed: 2024-10-23T10:59:52.000Z (over 1 year ago)
- Last Synced: 2025-03-17T06:11:24.001Z (10 months ago)
- Topics: bencode, cython
- Language: C
- Homepage:
- Size: 914 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.markdown
- Changelog: changename.py
Awesome Lists containing this project
README
✨ fast-bencode ✨
The cython version of bencode
[](https://pypi.org/project/fast-bencode/)





### forked from [bencode](https://github.com/bittorrent/bencode) to support latest version of python
- extra cython extension to speedup
- ```typing``` with mypy check
### Usage
```python
from pprint import pprint
from bencode import bdecode, bencode
with open("test.torrent", "rb") as f:
data = f.read()
raw = bdecode(data, decode=False) # do not decode bytes to str, use this to speedup. default is True
pprint(raw)
assert bencode(raw, bufsize=1000000) == data # customize buffer size(in bytes) to speedup, this reduces call to realloc
```
- There are alias function ```loads``` for ```bdecode``` and ```dumps``` for ```bencode```
- ```load``` and ```dump``` are useful for file-like object
```python
from pprint import pprint
from bencode import load, dumps, loads, dumps
with open("test.torrent", "rb") as f:
data = load(f, decode=False)
pprint(data)
print(dumps(data, bufsize=1000000))
```
### build
git clone https://github.com/synodriver/fast-bencode.git
cd fast-bencode
python setup.py build_ext -i
```