Skip to main content

A fast and correct bencode serialize/deserialize library

Project description

A fast and correct bencode serialize/deserialize library

PyPI tests CircleCI PyPI - Python Version Codecov branch

introduction

Why yet another bencode package in python?

because I need a bencode library:

1. Correct

It should fully validate its inputs, both encoded bencode bytes, or python object to be encoded.

And it should not decode bencode bytes to str by default.

Bencode doesn't have a utf-8 str type, only bytes, so many decoder try to decode bytes to str and fallback to bytes, this package won't, it parse bencode bytes value as python bytes.

It may be attempting to parse all dictionary keys as string, but for BitTorrent v2 torrent, the keys in pieces root dictionary is still sha256 hash instead of ascii/utf-8 string.

If you prefer string as dictionary keys, write a dedicated function to convert parsing result.

Also be careful! Even file name or torrent name may not be valid utf-8 string.

2. Fast enough

this package is written with c++ in CPython.

3. still cross implement

This package sill have a pure python wheel bencode2-${version}-py3-none-any.whl wheel on pypi.

Which means you can still use it in non-cpython python with same behavior.

install

pip install bencode2

basic usage

import bencode2

assert bencode2.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}

assert bencode2.bencode({'hello': 'world'}) == b'd5:hello5:worlde'

Decoding

bencode type python type
integer int
string bytes
array list
dictionary dict

bencode have 4 native types, integer, string, array and dictionary.

This package will decode integer to int, array to list and dictionary to dict.

Because bencode string is not defined as utf-8 string, and will contain raw bytes bencode2 will decode bencode string to python bytes.

Encoding

python type bencode type
bool integer 0/1
int, enum.IntEnum integer
str, enum.StrEnum string
bytes, bytearray,memoryview string
list, tuple, NamedTuple array
dict, OrderedDict dictionary
types.MaapingProxy dictionary
dataclasses dictionary

free threading

bencode2 have a free threading wheel on pypi, build with GIL disabled.

When encoding or decoding, it will not acquire GIL and may call non-thread-safy c-api, which mean it's the caller's responsibility to ensure thread safety.

When calling bencode, it's safe to encode same object in multiple threading, but it's not safe to encoding a object and change it in another thread at same time.

Also, when decoding, bytes objects are immutable so it's safe to be used in multiple threading, but memoryview and bytearray maybe not, please make sure underlay data doesn't change when decoding.

Development

This project use meson for building.

For testing pure python library, make sure all so/pyd files in src/bencode2 are removed, then run PYTHONPATH=src pytest --assert-pkg-compiled=false.

For testing native extension, meson-python doesn't provide same function with python setup.py build_ext --inplace, so you will need to build so/pyd with meson and copy it to src/bencode2, then run PYTHONPATH=src pytest --assert-pkg-compiled=true.

you can use go-task with task meson to build.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

bencode2-0.3.15-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

bencode2-0.3.15-cp313-cp313t-win_amd64.whl (125.5 kB view details)

Uploaded CPython 3.13t Windows x86-64

bencode2-0.3.15-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (176.8 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ x86-64

bencode2-0.3.15-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (173.3 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ ARM64

bencode2-0.3.15-cp313-cp313t-macosx_11_0_x86_64.whl (137.7 kB view details)

Uploaded CPython 3.13t macOS 11.0+ x86-64

bencode2-0.3.15-cp313-cp313t-macosx_11_0_arm64.whl (127.0 kB view details)

Uploaded CPython 3.13t macOS 11.0+ ARM64

bencode2-0.3.15-cp313-cp313-win_amd64.whl (120.5 kB view details)

Uploaded CPython 3.13 Windows x86-64

bencode2-0.3.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

bencode2-0.3.15-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.4 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

bencode2-0.3.15-cp313-cp313-macosx_11_0_x86_64.whl (134.1 kB view details)

Uploaded CPython 3.13 macOS 11.0+ x86-64

bencode2-0.3.15-cp313-cp313-macosx_11_0_arm64.whl (123.2 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

bencode2-0.3.15-cp312-cp312-win_amd64.whl (120.5 kB view details)

Uploaded CPython 3.12 Windows x86-64

bencode2-0.3.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

bencode2-0.3.15-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

bencode2-0.3.15-cp312-cp312-macosx_11_0_x86_64.whl (134.0 kB view details)

Uploaded CPython 3.12 macOS 11.0+ x86-64

bencode2-0.3.15-cp312-cp312-macosx_11_0_arm64.whl (123.1 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

bencode2-0.3.15-cp311-cp311-win_amd64.whl (120.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

bencode2-0.3.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bencode2-0.3.15-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (171.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

bencode2-0.3.15-cp311-cp311-macosx_11_0_x86_64.whl (134.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ x86-64

bencode2-0.3.15-cp311-cp311-macosx_11_0_arm64.whl (124.1 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

bencode2-0.3.15-cp310-cp310-win_amd64.whl (119.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

bencode2-0.3.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (173.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

bencode2-0.3.15-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (169.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

bencode2-0.3.15-cp310-cp310-macosx_11_0_x86_64.whl (133.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

bencode2-0.3.15-cp310-cp310-macosx_11_0_arm64.whl (122.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

Details for the file bencode2-0.3.15-py3-none-any.whl.

File metadata

  • Download URL: bencode2-0.3.15-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for bencode2-0.3.15-py3-none-any.whl
Algorithm Hash digest
SHA256 c01a097f3e35ce3fdceed6b58e2cffa92191b844e67151dc73c8c935e11f9632
MD5 1e07dd25b21eabf926d33d493d5e8b67
BLAKE2b-256 467b8bf04e1c6fb4ebaa7d80f49f6550219e7bbea0903f0f30a25085026264bf

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 bb8b4231b9b6396063916e80c8af7be5c9d29f456340b3268b5c446f4b6663f9
MD5 eaff5b3c090894ef74481c08ded0a181
BLAKE2b-256 9275ef95c908651892ce20788ead5e917181f60c1c4fadda323965705d49d58f

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f26bcd400945e7301a681cf839d986559ce9f8a600ace09f7d674078ae20575
MD5 ede834488e79943241aeabcb585b3aad
BLAKE2b-256 eff56d3faba41cd8c4333909ce09c095f1dc2e506c233b07d31e38a3a0f983d9

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8b55741b61102848bf0ab2b6eb8a8ad1d43a894c2bc27828f18613868b6a5054
MD5 3cb0b0ac0dd9de20a8ed6853248fddd7
BLAKE2b-256 ee57d83bb436c57070f99f3a7169e1d88503ec7175f859d5af402ea73c31e3d5

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313t-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313t-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fa16f1801c00e7c3cb98a58ee75360e014b0c7d2d750a0bf5839bf6a0eddd05d
MD5 c6a6f8d77f2075e2092c9104e8ab77e8
BLAKE2b-256 fd02f572581ff92a60b846b88e5136b4a0d36936e98ae99df3c796e3bf3bd6b9

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d43102e14fdf0ad029e08d30eadf11f1addead25062aa5bbaa094612bb38852
MD5 b5b9cb85262b4afc568ace9a3c69fa72
BLAKE2b-256 4cfa30c7d3fdd51b282fb57934126db77aea266480c5a4153db10136a441146b

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 984a7aaefe6e1f0a079817d4b4705c7161b778905ccc74f4cd72856e1c49f3e7
MD5 f1fe4c13f56beb7c21def19ee35c8d02
BLAKE2b-256 ce23c6bcd54609550e19ed955aa1c44c1d08e0f231289c8327cce45324e66e20

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf8bcf503d80eeead096b57fc83e89238bf64dcf9f5283ecb37e4b97c1bd72ee
MD5 acb21442957bfcbb8afe9e108c0be048
BLAKE2b-256 923ade0d6bfb9f179042f9c394e41cf9f6dacad6ea2f9cf29009fd660131db50

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5f7f0ff0d64b2d61cf7a91655910b65aa09e1fc29855f72399c0b99add1af541
MD5 f34924d385acddaadb4128ce10b00b1c
BLAKE2b-256 a99e2692c4f2e571f173db26208803f28695a131ae94bd0aad44679b046751a2

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f869b79fcddf714c368d6b8069052da17f383ea64adacb062942cb47e09da255
MD5 18406b8b92fd3621795c67399f9d1beb
BLAKE2b-256 c1e27db5a6c402c6a243081f6b76202f01c3dd3d8ee4d9a252d4fbc50e619693

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58691f4c0724cc1ba8bdbfba9278a1c1a906be598a2fcd4a84cbfa6f1e9137da
MD5 612b5d1180b0ebf27f5d2105cf70366d
BLAKE2b-256 1c61685738da240d682ca91898d81eabb8f3d0e28c9b25264e284f9b9920568b

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d80eb16d4fbc0630b7ad1282e07d564df3e2c2b2955b6f8a3dceec9ba8a5f732
MD5 5be657afa411183bb8f7b0a4e6cca82c
BLAKE2b-256 e4fe4c952a8ca03a496dd88383baa44398fd2ca40ba418ae7f193a51690dd7a2

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8e777c5e6de699e315e0f02ddd6a25db15555c222464d1b8f590913a89ca84a
MD5 15bf0ba54a73312836c6ec105aab2108
BLAKE2b-256 00df56b352a8c8ce0ea4b35848f5a95958466fd57ebda4ecde749437eaf54748

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c31eb672f7e2eabaff52ed3ced57e5f717fc492079ec9b2a38c345c68521e6b6
MD5 fcc2a735d97c2f38a794d9e096e3a767
BLAKE2b-256 96e4cf7a3227e501e724a98bcf72a6f50e604714ae2fbc7cff31153548422634

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 90c685df5fcd574c3cd2da8a8abed6386d85b669d34b16ec0ea8b74fb58d1700
MD5 d2d618b2f1f9324ded4602dd732f42f5
BLAKE2b-256 944a292dc018a65db739aa4ba82ed8f688eb9915519685d2f8b8124c033404b0

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b64c5b5406d9b927dc5298fb6261cdac65a4d5235ae6e6ba16abfa33b5e7f86b
MD5 155f7fdeee1ba920c5d8f53b664eece3
BLAKE2b-256 3ec5c175b99e98ddfb1463975c1c25fb12b7410dccedb4bf93911e31b78af2e3

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d91ef20694bd1b347e64de22c70185759812b287944af2a26681aaa0c7e551b6
MD5 98f75e3218e78350a1da73471dfb25db
BLAKE2b-256 764c477d2fa00714e3af59481b93106b9b9a87c22ec15781dceaab2383d08120

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b646571c4e07dd2411168b8a2c8a0640ca7bc566a7b59f6a243067981cb8110
MD5 f9007cf5ddc8c54484940bc48b69b5b8
BLAKE2b-256 1be15eaf4dcd041cd96542f8ea9fef1b407694bca2c7309a0f0be0b714bdc871

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cd1e7e90e03c366c0578d0291f1a6705da2e6795dd8da87c511d0209d8774532
MD5 6a211c9d5cdeb3cc47463b783d2be0a2
BLAKE2b-256 a27fcf0d494eea7e4066a2bac0847796066c1dd3ec9ad6e73bc35d7e3384bc40

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e7de97a6521dfce93ae0c3d7297a84d61f7c11b6aee320e9705c198afe06a935
MD5 05cc2e8370d05892f7f0f2d54c1cbb47
BLAKE2b-256 1e3713ffb316eb805b93a34acfbc77d7f0f5a1e174dfcd605f9c35c653020802

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d4c5005e19399eef2aad632c8c764ef0df42e3a7eb109027b2536a3c91c2f4e
MD5 2839aca74090fac837a8930f2e99b225
BLAKE2b-256 c092c7a228763f284bd1aec54b4a67005a6e35ac29ef18e037aa2d4f9e247d8a

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0a52030ec01b1cedcd50a69fb4b3b9b5bbaf4f51d9820111e8be8a52cc0e2efe
MD5 3eec6cc62b125d3b2d6c86d3812d92ee
BLAKE2b-256 9a4809503391261d4669ffe897de06a0ed11696b6b33ac9d6963d6e595659fb0

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 430aface79062b773d0cda8c76474fc398cb403af7fff1e0f5bd19d7d38b0a58
MD5 b7dba214cbd338a3ae9e4fde932d7ff1
BLAKE2b-256 d5922a521487f50e34711ffa3f33430551c9db4dc65641155fb3f9a5c25f5172

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d676374e2a67f5591046f182ad3694f6e1de6408685aa91dcd75e2c7a4967c0b
MD5 e4c408ad7809bbfa152e72f879b23f7b
BLAKE2b-256 3905e33313ba27caa2cae126b2fec6cf5d5ffae4a66fe7cbb50cc4d87ce057d7

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bfb93216a36cd39c1a09331d941f2bc062d01128d33fccda509ddbc2e095f772
MD5 415f295e6cc4cf7e8e71e091084d581a
BLAKE2b-256 df285d16438563e07de0577258115f9a051d503c2394d2c6254ec36fc319febb

See more details on using hashes here.

File details

Details for the file bencode2-0.3.15-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bencode2-0.3.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a78aa9f27656630a3379c7f58b7e0f93ca4d92830943d6133198f5a2e79d4680
MD5 c0ea3c5c6c51de277190e4e563d52992
BLAKE2b-256 6d7ccd5a22441d5df1cb2c87146f910504b71e97680d2aef3da2dba8cea9149e

See more details on using hashes here.

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