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.17-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

bencode2-0.3.17-cp313-cp313t-win_amd64.whl (124.8 kB view details)

Uploaded CPython 3.13t Windows x86-64

bencode2-0.3.17-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (176.9 kB view details)

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

bencode2-0.3.17-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (173.5 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ ARM64

bencode2-0.3.17-cp313-cp313t-macosx_11_0_x86_64.whl (137.8 kB view details)

Uploaded CPython 3.13t macOS 11.0+ x86-64

bencode2-0.3.17-cp313-cp313t-macosx_11_0_arm64.whl (127.1 kB view details)

Uploaded CPython 3.13t macOS 11.0+ ARM64

bencode2-0.3.17-cp313-cp313-win_amd64.whl (119.8 kB view details)

Uploaded CPython 3.13 Windows x86-64

bencode2-0.3.17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.1 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

bencode2-0.3.17-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

bencode2-0.3.17-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.17-cp313-cp313-macosx_11_0_arm64.whl (123.3 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

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

Uploaded CPython 3.12 Windows x86-64

bencode2-0.3.17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.0 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

bencode2-0.3.17-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

bencode2-0.3.17-cp312-cp312-macosx_11_0_x86_64.whl (134.1 kB view details)

Uploaded CPython 3.12 macOS 11.0+ x86-64

bencode2-0.3.17-cp312-cp312-macosx_11_0_arm64.whl (123.2 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

bencode2-0.3.17-cp311-cp311-win_amd64.whl (119.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

bencode2-0.3.17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bencode2-0.3.17-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (171.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

bencode2-0.3.17-cp311-cp311-macosx_11_0_x86_64.whl (135.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ x86-64

bencode2-0.3.17-cp311-cp311-macosx_11_0_arm64.whl (124.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 Windows x86-64

bencode2-0.3.17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (174.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

bencode2-0.3.17-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (169.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

bencode2-0.3.17-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.17-cp310-cp310-macosx_11_0_arm64.whl (122.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bencode2-0.3.17-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.17-py3-none-any.whl
Algorithm Hash digest
SHA256 883ec41236e96971d6303a203abb5ac1efe9726b39067379d9603ee46a8a7d8a
MD5 b68138b0f6c07d4c059dd740b6615943
BLAKE2b-256 8b3e8447261869ae15c25deccd197484d2c2af0a68f0cd9062c088fc2d40fd14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 96450962f01a0e8fb677f3f2f8442587bbbe8b4091f22273bdfbe5d7ead23742
MD5 d8f76bef42e7844ca760742baf4c4731
BLAKE2b-256 127b527a206666dcfc570c228898dc3079cefcd12a03eafdd8718d9893593209

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b5b3ab21eeb246b98107679849c9b973b52ea096bc5c8ec3a8101d0db054de0
MD5 a5b26db13a92b72f799c33a34d1a492f
BLAKE2b-256 240474e2771339a36ff3fb8d8128ed8b8a7ee17dac91f697f1019e71b712f955

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b2f8782127bf518f46bd95cb343a76c89f794481379d0e3ca410637a9c2c3ea
MD5 18299f4150dcbdaaee5282bac6444a85
BLAKE2b-256 2fa06eeb6212b360967ade2ba58094aae63bb9e04b0761c3b70303edd5c7630f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313t-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3c139357710c42f61ac3264de7ba9502b929c12b180e3a1cebd4fa77d1ff2ce1
MD5 4d17ab0b5d745abb0f02d7be9c44286e
BLAKE2b-256 2374e02ff9178051975a3030491066fbe83896a04bfb65d863165a8e8d9f43e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0feb1a3364caa4c748d60a1844524c5d5d304fb493d9d47647418c46431b95c7
MD5 ca9ce8b20d974f83fba5ba34967be6e7
BLAKE2b-256 5689ea9b5b42bf32db3481c56426a435fd83f6f96f3435b082abe6d89bc4af2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 13f5275ce6d8e371b9407cfa52ba0ee3be82e4f3f09e6075b70d26dde18b57b5
MD5 94015c7d01280907115ca6188d96f6d5
BLAKE2b-256 a0d8e4de9603a4303e6901d43812dd3998bafcc647bcc34743ed09aaddbd7648

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6cdce7bc767a7c14ee1923e1c36f2bd29fb5373e4b7f0ae565bf71e9eff7ad71
MD5 62ccef8901290fb1c57c731883ee0e46
BLAKE2b-256 d3966a9b3074056656e91679f256616f80873772bbf3f1fd4dbd037588cb434d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 119e8f9dd18758618287b3afb67b3663238bfb2b5f69257d27a8ef9ece811c9f
MD5 24aab805503ee78a7dde4210484b802f
BLAKE2b-256 39a31e828239c58c673eafedebd3411f7777d22b3e2ccc8366e0a362da7ddd75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 005179a17dab1b1ad42e2e5cd71bc4aae79bb49b7c6f53c34f0ec295dcb6e9e0
MD5 7be5f0aa8de8fcf45b7eab89d03bcf53
BLAKE2b-256 4ea37483c86c89cad6f58c40ed13a5081d532f8a218190443ff186ffb0a22628

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8c4dc93432b54a45655845499fb9c642eb0db14b0281c6f953be853fe4cfe98
MD5 8c2aaa0f9faaa40cbeba4329a04c8779
BLAKE2b-256 50e0b67a70da3a2b87cbf4f4d44147e8d1488bf5660343bc8418864c18624d55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 77b7f64b665bb80961e4a296e8de1112091d8724fb2c8566c36a472df3970890
MD5 afc6308724575d4ba8c0bd6a4c4e6907
BLAKE2b-256 19fdb3092742054278cf02275fddce76997a3d6244b6c65895135b63024bf94a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 26814490b5065a37110b35bd9f4cd58b30fc4e561415218c2a431da37f638abf
MD5 228bf454f26e4f20ca6048b3e1911d45
BLAKE2b-256 aec8f2c1d0a6cb6cd211cc7e53d6715264b80eb5c18658a7557945685c9115dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7f3d8b02b6ed73c4e957d46f18307f4fab66b3256e60c28ed2d1b0427c2cd5c6
MD5 2c4febebd3997c0895f34a153f7e3a69
BLAKE2b-256 c832aaeeefcf9c871c0ed74c31fb71f2fc60bd2811ff9a839d7672e71b4beff5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 cdf1392aa42dc23b9b4a003ee4a4a63d8de39ec19c7359a2d70f361af04d6bd7
MD5 f6f7e11f44091a12ed62472916bdfc03
BLAKE2b-256 6a3bd54c16ffd338e1905b5ad6dfea26e2581a821ff8ffac7a2df044e9eee959

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d251777927e38a29c4a7e273d1c96c87b5f9c3ec10e03ad69063f505e9552fa8
MD5 f5ccbb448dad22b724c690839a959ba2
BLAKE2b-256 f2676afeae61e6cd07545a8b2a3a1bf09ee14de6bc0cc3a77fba273028aa68ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c00ef012f9f157751307f939bd0f8d39086662630691a3b498f4a46d699fdeb1
MD5 4424b123b6ca8e047acde0174e588071
BLAKE2b-256 bf7692e7221d329d5e31ba58774ef8a5616568fa1b0f706fa33d25f100e7e3b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8f145a6598ad58651b147db6600166beedd0954b77f59425c830779c3d9a4e1
MD5 b4afd52d80bfd00da7fb2fbcb9b5c361
BLAKE2b-256 f25818b97fcfaaaaa6f12ab96b75fb51f6028200af9d001dd7a8ecd9f0156f7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 00f8071f32a96e51bd2440b7f14f0095718816749f60db814ab5e3a0c874395a
MD5 f53cf9add1fd07713e6d4536e7db678c
BLAKE2b-256 f6f49e495861a6fc93ef28db451a12d9d38948b2036625ae615f8acb0dfeaf2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 118342ad31bb41c4a40e4e04acbb3df29bf6dc5710a26b9c9486bee0e9b8f960
MD5 02dea5444e850241cc38bcd70e58ffbb
BLAKE2b-256 6999413bff355dc7ac3bba75013684319475f0e2e1887e308ae999d34a99900b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f10c21c80348187c45021e6da5abafdaf853121ce65bd1ad4621519c5be580d1
MD5 cdb723e6e053ada94c0db0c99de2db23
BLAKE2b-256 f6723f9171c4810b501fe3b68583b2c16347a9246a170adf748379eab3f823ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9fd9ece33a80de4b505ccdd74b55a5064fd845f10e94de37b455df59b130f1ea
MD5 9e0140274266626001e7247da67a5124
BLAKE2b-256 b89dd5cb38244dc5d97df1084f10bf39eac03e6b56474b0192498fce67e58076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93d77b7a597538479ca5b82e9788588ec17a4ecd4c315466978730162fb400c7
MD5 725c9e26894462822a78513693926b31
BLAKE2b-256 7904a0c11e8391e06730f376f8eaadc1311755c83a05400f3067d353896beb0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0f1cc96c5f783fb99047f8b360eaa60c021aade24579a43ca8cea009d14ae356
MD5 0f74c864d69d7da35b744f4325c3e03d
BLAKE2b-256 1d714bf8e5b6451e9cd3e430af3f568db1db0143df9342c18fcf5275bb5c4aa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e0b1515a0ad33522b7e76c9ed463529597298cc11e51c90f2a3b894844a8406d
MD5 1754e5e2818cd93aac07d1c86c3d337d
BLAKE2b-256 50118093fb2f56367a912d65db9ed117e2c47349e11770272d9d1a78c3d0f0f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.17-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 637beeb7e624a5278820a72367187ae1172a283e399f68b17b0ac98e72088b07
MD5 65c6323d6abc1f47adf1ab8cada4eca4
BLAKE2b-256 a4844c8b5824176f5d3448e8e016899f1b356e5aa0f1465e69ffadf1caaf128d

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