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

Uploaded Python 3

bencode2-0.3.14-cp313-cp313t-win_amd64.whl (125.6 kB view details)

Uploaded CPython 3.13t Windows x86-64

bencode2-0.3.14-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.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (173.2 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ ARM64

bencode2-0.3.14-cp313-cp313t-macosx_11_0_x86_64.whl (139.5 kB view details)

Uploaded CPython 3.13t macOS 11.0+ x86-64

bencode2-0.3.14-cp313-cp313t-macosx_11_0_arm64.whl (127.4 kB view details)

Uploaded CPython 3.13t macOS 11.0+ ARM64

bencode2-0.3.14-cp313-cp313-win_amd64.whl (120.6 kB view details)

Uploaded CPython 3.13 Windows x86-64

bencode2-0.3.14-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.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.1 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

bencode2-0.3.14-cp313-cp313-macosx_11_0_x86_64.whl (135.9 kB view details)

Uploaded CPython 3.13 macOS 11.0+ x86-64

bencode2-0.3.14-cp313-cp313-macosx_11_0_arm64.whl (123.5 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

bencode2-0.3.14-cp312-cp312-win_amd64.whl (120.6 kB view details)

Uploaded CPython 3.12 Windows x86-64

bencode2-0.3.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

bencode2-0.3.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

bencode2-0.3.14-cp312-cp312-macosx_11_0_x86_64.whl (135.9 kB view details)

Uploaded CPython 3.12 macOS 11.0+ x86-64

bencode2-0.3.14-cp312-cp312-macosx_11_0_arm64.whl (123.5 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

bencode2-0.3.14-cp311-cp311-win_amd64.whl (120.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

bencode2-0.3.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bencode2-0.3.14-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (171.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

bencode2-0.3.14-cp311-cp311-macosx_11_0_x86_64.whl (136.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ x86-64

bencode2-0.3.14-cp311-cp311-macosx_11_0_arm64.whl (124.6 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

bencode2-0.3.14-cp310-cp310-win_amd64.whl (119.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

bencode2-0.3.14-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.14-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (169.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

bencode2-0.3.14-cp310-cp310-macosx_11_0_x86_64.whl (135.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

bencode2-0.3.14-cp310-cp310-macosx_11_0_arm64.whl (123.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bencode2-0.3.14-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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5ed723cea992783dfad046bbe68ed1296ea768454ad3a6125ce9ecdd327e5eaf
MD5 9ae98bfa416994ff7854c3609c8cc187
BLAKE2b-256 c6af01975d70071e59399fe43e326ace1732241e0529d5ef499479a74220f852

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 36de137ca9229a1f915a2fdd5569550df41276d4356bd897876bfe8257451a12
MD5 08817863904c8a0eeb578e22562e01b1
BLAKE2b-256 d03439687a476bd9b9979122878937afa9a858ac1adeac76d448c48cc4276b78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97acc476fdf63e01e9900a54cc498a28918fc9929de60c2f699f2372837b104f
MD5 b4109bc238d2937b35439c3b0a25dfd3
BLAKE2b-256 51ed3dabb44a0a2fbceec9032851d053a997231cbcddab1afa1b810c7ce02c15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0abb886afd814a0fb55896f25904ae66d435879e02ff0f795e2a570a2494586a
MD5 624add1c4b290bb053bc4836717069c5
BLAKE2b-256 324ee463fdc450880a90e12bc4c36ad046efdc34303ae3713ea5dc4dfbff1725

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313t-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5d81cd356070bb343f7f3b5f0133d670f4ad1821279a681993ba31f36304f0b1
MD5 08df772123c39d136fb64f69d88ccf83
BLAKE2b-256 e932c4eb6e690a80565ec19513becaccdd170051fcc6d88843e6147faab4e387

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af6b636197bd9f6633850a901967bdaad6aac7cc25848f967bcc6699a3f5e439
MD5 83a95f21b67ab9d0df3992aa785ddecd
BLAKE2b-256 8019410d292f984a190786051fda79d4545d3016eabf8a29059f97259d3c44c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 655da293a370ad4149cab84f5095ecc2a8e9c78d951294282fe7ddae58abbe12
MD5 cd2a3812df50a1f5911f9afb88b04404
BLAKE2b-256 d95798146c52547e2e1f84e163355c378df7369d335cb03932e89e8b480f00bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6429183b0951136eadc088dbd744fbce3e1cb65ce8e6aff5dc46d45ce4e54ee7
MD5 bd6addcd175fb48c6af5d62cae81f485
BLAKE2b-256 4713575e615af999b1a59c04a87d44453db2458bb996826d3c7dc9abbca1689b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 df68bb941cf731a121f242146bd905314b5ddc93010046286d45a2beb4a0ff7c
MD5 5d862a7d6dff74b59c8b376a1c69eb62
BLAKE2b-256 2cea3414fc9a158a0ad72429c7d9c3222dde2d9fcf433436969c8e0b28a9b91d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 60d03aa01182df2ea7dca00243ee062b2e5c40fd801f312c52b69009e88bcaee
MD5 fee508d5525b845914d2e34cf3b1d09a
BLAKE2b-256 de268a109c701b4bdb3717d09ef9026cfb5dd458a536a47d3434b372e3daa296

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e1f1ec3e2f7af20c7b2afbf3b70edf494699194b203ccaa004cbe17f2e10d25
MD5 af82bf8ed12df5e6a1c3529f26f501c2
BLAKE2b-256 425a29351110af3d707feb8ed48509b483c8eb7e02bf6029cd87ac79836d0db8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2d41f86cac09d8d44a9900ff7e2df7656b885d9acd2de741187c78f8bcbc7714
MD5 5f3a8668c0603e1ee595afd73a15ee93
BLAKE2b-256 06a3c61cb6f902e99112febf208cc47224f91ca6a13786b3a212555822529c95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc53c250bca23c2c00881db3fd268f58b5a7d877233d15245402d665dfbba1bf
MD5 f2e8bf8e3fb4f18056f74a064945fc0a
BLAKE2b-256 5f47f0c44e4fbf27867dbacc354a4e4ac1e22ddd12c9a6db57052cf84dfcb484

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 98246e34c710b39804959cf259da6e0ff649e8273fae511969098a2678472475
MD5 8c49463d84161cea9b4c57d736347796
BLAKE2b-256 edcca4ed06932d27dadef031b734a030c3024805f758d1dbeccf13d1e7a1da8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fe7d915b84a269ad26933d19b8ecbfb54924f622091fee89fabc3c016dfe157e
MD5 a7ea3ae01c621578a075a9b28f49a908
BLAKE2b-256 465356a191114f5bf8752e6d013eb49b3d2cd80d60f2435a9af6294982057d9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f564e24661ba52205bd4f333b046da08d9cfa0af09ea70113f5e3e279df42776
MD5 166d3a9713616007bd97182d1d4d2c3e
BLAKE2b-256 8c0e6e743426ab623fca5779d05e3f4fdf079442c5d93d4d2acb2f08eb1ffdc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 174ab768be7e94c6ed88571eb888840bbbba51c14f9792aa467d85c8bcab483e
MD5 3ba45ba6b5e4a29662f9ff8ce6d16045
BLAKE2b-256 f41da99e0614df056754131c18065f62c141caa78123f337f1eae5956e314256

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54e6be0289328f2d48dea50f049117428bd049bf9d737ddf0ad9f718bedcfce0
MD5 fb5f97ec35252745fe66ee6a0e29d080
BLAKE2b-256 23d824264223853859e871abb528c72afdc2c0d799a7e38068805b0e7e8ac67e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9697e0c5a783a9bbb42956544b6691c151223541b997b3e11342e1a745c65115
MD5 be051b5cd03613586fc86609625030ec
BLAKE2b-256 93083e2bd80041f8c4cd46a62292172f0b284e1f4f8ec547584a363141986ca3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bcff709094dd3a751bb7e409966404b4ac1204e31ff1a9e3878a391ce13b740f
MD5 a068071837c14bbff726fe1ac0b3a0cb
BLAKE2b-256 2189171a3ccd6c098613f492a9e07c173356270cd2937ca36a0d1f395035e896

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 febd28c8814727855487137b3ee9e240df07493ebebf064c49888004d5a586e6
MD5 5ff74ff577c6c2369a387aa1fa00d960
BLAKE2b-256 b6af710521f9ddd7545216788dbd6ebb86f5a5e8bd8082aa1d91d8a1f6b73285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a2cf62282446420ce9196acdf84122b3cf664c32d227ad43cb5a25e8ceb3faee
MD5 1f0ff0dd8791df84b93dfbdb73148fef
BLAKE2b-256 aab4c5a8fcf6a4c0915c07e165b5febd42e971e6b1e7e92c14f2ac771b17f8bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c76c7ebd97db5a6087a76daa9a2e8e57d964b670a8762c434dd7e6335a323d23
MD5 5fb1cf2984a73f7a7117cacd985da8d9
BLAKE2b-256 40393ec5fa30852d5e965873fb64ab2706f58e44d083324ae76ba804f4c6ed90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 340aa17370aba8ff8882e1d968c3c5eff8ef57129020eea81b0cc1512a77abc9
MD5 7caba2ff0a22040ad6b3956c16ea6051
BLAKE2b-256 0afada87fd2c55e7c86dab00fb4f08ebc9571f8a6c308a01230dae0335c29697

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 21d858c78bb163a378719964d408d9d945d057535373e9457b829527a4350ace
MD5 6769d66adecfff71ba3c051d29e7e3d0
BLAKE2b-256 c7857dfc185181a734d2b76af8d89db807e07c6297aa3c583485633e6d126cc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa922a01da9456810e0e058c012cdce45339f9e20ec6456c5482df79b2cc460d
MD5 f0135f11ca1bcd27bfd47987dba9b14d
BLAKE2b-256 06c8b9b4c565eb03030776359b0f5023efc6c0c625fb82dcb57fb938e3bee2ba

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