Skip to main content

A fast and correct bencode serialize/deserialize library

Reason this release was yanked:

bad release

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.

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

Uploaded Python 3

bencode2-0.3.12-cp313-cp313t-win_amd64.whl (125.0 kB view details)

Uploaded CPython 3.13t Windows x86-64

bencode2-0.3.12-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (177.8 kB view details)

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

bencode2-0.3.12-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (174.4 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ ARM64

bencode2-0.3.12-cp313-cp313t-macosx_11_0_x86_64.whl (139.0 kB view details)

Uploaded CPython 3.13t macOS 11.0+ x86-64

bencode2-0.3.12-cp313-cp313t-macosx_11_0_arm64.whl (128.3 kB view details)

Uploaded CPython 3.13t macOS 11.0+ ARM64

bencode2-0.3.12-cp313-cp313-win_amd64.whl (120.4 kB view details)

Uploaded CPython 3.13 Windows x86-64

bencode2-0.3.12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.6 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

bencode2-0.3.12-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (171.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

bencode2-0.3.12-cp313-cp313-macosx_11_0_x86_64.whl (134.9 kB view details)

Uploaded CPython 3.13 macOS 11.0+ x86-64

bencode2-0.3.12-cp313-cp313-macosx_11_0_arm64.whl (124.1 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

bencode2-0.3.12-cp312-cp312-win_amd64.whl (120.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

bencode2-0.3.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.9 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

bencode2-0.3.12-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (171.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

bencode2-0.3.12-cp312-cp312-macosx_11_0_x86_64.whl (134.8 kB view details)

Uploaded CPython 3.12 macOS 11.0+ x86-64

bencode2-0.3.12-cp312-cp312-macosx_11_0_arm64.whl (124.1 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

bencode2-0.3.12-cp311-cp311-win_amd64.whl (120.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

bencode2-0.3.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (176.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bencode2-0.3.12-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (172.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

bencode2-0.3.12-cp311-cp311-macosx_11_0_x86_64.whl (135.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ x86-64

bencode2-0.3.12-cp311-cp311-macosx_11_0_arm64.whl (124.7 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

bencode2-0.3.12-cp310-cp310-win_amd64.whl (118.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

bencode2-0.3.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (174.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

bencode2-0.3.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (170.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

bencode2-0.3.12-cp310-cp310-macosx_11_0_x86_64.whl (134.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

bencode2-0.3.12-cp310-cp310-macosx_11_0_arm64.whl (123.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bencode2-0.3.12-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 914179caa4250e522333ffebb590cb99a9fb3319eb06a2bd0ca0f109f45afaf9
MD5 079286b974dc3727ad2c906719016c16
BLAKE2b-256 cd56e9e3d1a3a379af93beed7341b9b2cd3afe3259071212eb3d7aae47b16666

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 dec226a85404b3001963ac1d391338cec51889a270ffd4f1de33b59f3fdd4e30
MD5 9d197fcf2317e5347f6c02241b62d2c0
BLAKE2b-256 8b5db3867ef021af30cadc42b26b1bc114b57c89a2ce5e90184b45acdbbc2270

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86ae6217e16c7a8eb5e04bfe75cbdceefbc5759bd52026bb2d0eef6e3391728f
MD5 d51e9ca0296078526c7b65d9fb268e8d
BLAKE2b-256 7b3d4edfeb9a76723d54f0404afaf20f92e8ab64be8fff6d37bfb710c217c5ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84a5a4ce722aa94ca94fe62783d7225bcafd52a188c91d0309347be2f7c08175
MD5 43dc281b70d2cfafa7e9a0e1ef95846b
BLAKE2b-256 5c66b9a0570f4335e9c11563c510915a1767bdf6485035170241d2bd38ddbe3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313t-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 1e514d37b31e14bb23c89ac3f298c30bf3f098309948cd71403938abf9517a4c
MD5 82a20b7870c6800c374b289bf79a3982
BLAKE2b-256 44ab38928a531ed87d173c937f4fb01c58cf559dd2315349202ace8789248ebd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1f1ee14aad0c6aeb3783dca0e925147eddec9196feae7c87a07def55fb7dd2c
MD5 dad8926449d32f543fd315a49728bdcd
BLAKE2b-256 6800624028361a8f9b0364ec986a14d50e0ce1697fc702fdb42d696daf4ce887

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 207306f514a534234cdd30b23a82d86a530e67eabeb70958fc6cac7362a55a90
MD5 088dd0114eb5eb1b539bcf24be7fb958
BLAKE2b-256 b9e6be1c49496d3fe9940f48418d2f3eabcdcd01446b55a3cd74c375ad8b5ff3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29ff974b458a5560debec0017e25c016ca8ebce6aecdeab46e40231b9730c2cc
MD5 eb2869cd1393ab00eaf613d7a7fed77b
BLAKE2b-256 dac7bd511f178c051037b30ef307848b9ac071a89c62422e73c0c703002cf605

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ec80eebf5ae3f0fb768fb13048e8e19544cdeae8043fbca07db89d4f60b76958
MD5 aee8d4d8a1d93afc2c95b0826a169add
BLAKE2b-256 2781f2e51b257ac8eff84f6dd5b0daf1d135463dc8fdc998122c805e56a7e58d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0197388c76b3ace8e3dddd6c9fbdaea53b7921547db6760ace5b0aadae2b896e
MD5 e96bb3d916939952264ec76139b29712
BLAKE2b-256 4809f93b06259f261c9d90cf638840e956455ba39b0fcadf55be2810715d6693

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb46d8cbce4e2bd82ccf471b5e6f365b943a2d9261f13b359e42a5614870ea40
MD5 92fd894fc938c69a65bcb65ae04dcf1d
BLAKE2b-256 575197c6cef26b7f13b84167d34570d3e241a36a14060ed46f59701b686f95a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3d52131ba40375ca80617b1b44e86e94b09d95fb532fa0a1d802ebf7fbc21228
MD5 286696dd6a1258c0d95a2524e9f4088c
BLAKE2b-256 6289a29b698a78d0f57d4aa40510ed377d49b8633124b5fb22bd1f766492a89b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e51e09264f3226b510bac14785aea9b7b8376ee62bd590209c757018f199075
MD5 71854da8afc14bb4214218341b265e30
BLAKE2b-256 ab42218ad82dcfc8edcdcc7acaedbde22aae872b22e07983c3fb8c4ad04dd088

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e66c021d47f6882bbfc32603f9bad0acd3184a0440302edd398d74bc4e8782af
MD5 83d31f64b804fed09367bd766e690df1
BLAKE2b-256 a18ef2abcc60d0698b734c1c04ca3f9d332961a20d09d67c9903ce2a5e4cde6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2076512b0fa26d23488636d6a762d5d57932a7235be90904135ec7b68f9b42f2
MD5 a537a473133ec27f16b10ea5f310221b
BLAKE2b-256 bb2e9ecda4fce19a360e5304c5b01514b7b85dcea59d583afcdc773ba8b5cb35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dcefbf149b2db00b56e98dc9738db5a5fd5f53f4d475473df578f59f7f514ed
MD5 54ecde5843cded90da20b81d0698885b
BLAKE2b-256 0191fceabb504ecb1afd6ac5b7bc85cc62f86fa628d22b57a239bdbebb338a23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 74a848cec34275460c76e756dce45c12cac8e8970dca2843de042e76afcbbf34
MD5 af30f3b9d1a98913c2c3de0b89918f5d
BLAKE2b-256 34297874b1730f0f9030294dc56a05865ff876698f456f3aa941567e40fc0440

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5267c3b0dba143ccd6cd60711e73a4e3497183f31bf7238b6a8ef98fc8521927
MD5 29997fd85287fde8d7a345c2f6618d6e
BLAKE2b-256 d5b4cf1783c3248b0c9d5f810dbff7e7d4c2864fc05ac51dcd6f897d57db08a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c56f3fc4437a7c9629eaf1a7e7f8cda99b1982b03ef3f237399afa2a3c4808e1
MD5 01a758ae9d3f8520457f5c10d270bf1c
BLAKE2b-256 75f3c23c783c111e750d3002d5a03fad732af2dca1cae65dbe34d378dd363b8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 8d4336bb477bc087741fb35017e69a1faa52de9644300c0c4df518c29258a823
MD5 5cda23f0128e240a4ae8ff3db0980ac9
BLAKE2b-256 902097fa921d72205c87260f6b5fa113ca09cbc71ff3deeeefcce03da9bdcb69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd8ccf60fae0858b52a0b6e80b8284dcf90fc38da920162b4b8bfa99c9892406
MD5 7af86e6ab94a26f84c05e2f0e3553bc3
BLAKE2b-256 4efaef6dbd3d3136fbf88d9b71fe3776ac1f8ac9eb750c162b5ba51770cd3ada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9a3e2f9cb5d185e6672c6677aabdc4241c2b2b5f60f847b247abfb2c9e78b024
MD5 7eb3ad4c3d582b2d517eff1eacbe24a1
BLAKE2b-256 2438b355af1abe10e155fb44143603364cf8690ea6bead7866b925277e1dac2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 835be803ec34c7fddd36edd864a7d6f91009ca4acce5b37be4744e9ba93b4818
MD5 a10b8597b8e24547d58a844238befe37
BLAKE2b-256 c40582b37d0d4e0b3a8464a1cf8a9b7bea48e2d299c75a35242c0741b559ce1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fdaf73f5a61c57be06c672e65bece8b58fb5a66a98d9ee3860b366c50ce6b553
MD5 bbffb07c0ba68bdf79a4a3441151d576
BLAKE2b-256 cbfd387b2b6e44ede8060c33384b6bfeedfcd49e31ac19f5756ac2c97c3eebf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9fc955538cd71eff850a316c2cd8b07dd50604bbf2a1810a1d4fe1bd40bf2a9b
MD5 3fc8d498f339fa3abf8887a228285a2e
BLAKE2b-256 c014041789e4fccf4c02f699865897898755bc4c3b9d61c1e926503975020640

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bencode2-0.3.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31b8661bfa411179970bab02808908c80dfba5e0a5d53abc7efe6562294b959b
MD5 e0cde02db4b7406236597361702ea5ab
BLAKE2b-256 6c1e0532d142f47bd03e6debeb5c811087d9b2fb360afae8010178b52137ba6c

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