Skip to main content

Bencode.cy

PyPI License PyPI Version

A fast bencode implementation based on Cython, supporting Python 3.9+.

The bencode functions are 15% to 230% faster than other compiled libraries, and the decode methods are 40% to 320% faster than other compiled libraries.

On average, they outperform pure Python versions by 250%.

Based on my tests, it is currently among the faster bencode libraries available.

It is written using Cython's pure Python syntax, so it can run directly without Cython compilation. Of course, performance is significantly better after compilation.

Installation

pip install bencode.cy

or, if you use uv (it might be better):

uv add bencode.cy

Usage Examples

from bencode import bencode, bdecode, compiled

assert True == compiled # Check if the code has been compiled with Cython

assert bencode("WWWWWW") == b'6:WWWWWW'
assert bencode(233) == b'i233e'

with open("debian-8.3.0-amd64-netinst.iso.torrent", "rb") as f:
    torrent = bdecode(f.read())
    print(torrent[b'announce'])

Speed Benchmark

bencode.cy.encode and bencode.cy.decode are the Cython-compiled versions of this library. bencode.cy.encodepy and bencode.cy.decodepy are the Python versions. They are the same code—one compiled, one not—which is quite interesting.

bencoder.pyx.encode and bencoder.pyx.decode are the encoding/decoding functions from the bencoder.pyx library. However, it currently only supports up to Python 3.11 and is slightly slower, though I learned a lot from its code.

fastbencode.encode and fastbencode.decode are from another excellent library, fastbencode, which is written in Rust.

better_bencode.encode and better_bencode.decode are a C version of the bencoder library from better_bencode, but I don't know why it is so slow. Maybe Python 3.11 on macOS wasn't compiled to C.

bencodepy.encode and bdecodepy.decode are part of a pure Python version of the bencoder library from BencodePy.

From the comparison, this library is currently among the fastest options. You can see more detailed results below.

deocde benchmar result

Name OPS (Kops/s) Mean StdDev Min Max Median IQR Outliers Rounds Iterations
bencode.cy.decode 521.4145 (1.0) 1.9179 (1.0) 0.2650 (1.0) 1.7500 (1.0) 36.3330 (1.0) 1.8750 (1.0) 0.0410 (1.0) 2174;3385 40001 1
bencode2.decode 490.4606 (0.94) 2.0389 (1.06) 1.0887 (4.11) 1.8750 (1.07) 201.3750 (5.54) 2.0000 (1.07) 0.0420 (1.02) 1082;12577 134085 1
bencode_rs.decode 485.7196 (0.93) 2.0588 (1.07) 0.5006 (1.89) 1.8750 (1.07) 64.9580 (1.79) 2.0410 (1.09) 0.0420 (1.02) 1664;16625 153847 1
bencoder.pyx.decode 191.7128 (0.37) 5.2161 (2.72) 0.6630 (2.50) 4.8750 (2.79) 95.9590 (2.64) 5.1660 (2.76) 0.0840 (2.05) 1254;5630 68185 1
bencode.cy.decodepy 164.2124 (0.31) 6.0897 (3.18) 0.6805 (2.57) 5.6670 (3.24) 97.4160 (2.68) 6.0420 (3.22) 0.1250 (3.05) 829;2364 66116 1
better_bencode.decode 134.0034 (0.26) 7.4625 (3.89) 0.8133 (3.07) 7.0000 (4.00) 84.9580 (2.34) 7.4170 (3.96) 0.0840 (2.05) 499;3408 34238 1
fastbencode.decode 123.1785 (0.24) 8.1183 (4.23) 1.1346 (4.28) 5.0000 (2.86) 107.4170 (2.96) 8.0000 (4.27) 0.2920 (7.12) 1585;3315 63493 1
bencodepy.decode 103.0055 (0.20) 9.7082 (5.06) 0.7732 (2.92) 9.1660 (5.24) 84.0830 (2.31) 9.6670 (5.16) 0.1670 (4.07) 636;1559 39089 1
bcoding.decode 53.2570 (0.10) 18.7769 (9.79) 1.7134 (6.46) 15.4580 (8.83) 90.7500 (2.50) 18.9580 (10.11) 0.5010 (12.21) 1638;1730 11205 1

encode benchmar result

Name OPS (Kops/s) Mean StdDev Min Max Median IQR Outliers Rounds Iterations
bencode.cy.encode 287.5983 (1.0) 3.4771 (1.0) 0.6224 (1.27) 3.2500 (1.0) 57.9590 (1.0) 3.4170 (1.0) 0.0430 (1.0) 565;8949 57143 1
bencoder.pyx.encode 256.2142 (0.89) 3.9030 (1.12) 0.4911 (1.0) 3.6660 (1.13) 93.9170 (1.62) 3.8750 (1.13) 0.0820 (1.91) 1054;3805 97163 1
bencode.cy.encodepy 188.4005 (0.66) 5.3078 (1.53) 0.5279 (1.08) 5.0000 (1.54) 72.0420 (1.24) 5.2910 (1.55) 0.0830 (1.93) 1188;8115 83620 1
bencode2.encode 183.6796 (0.64) 5.4443 (1.57) 2.0376 (4.15) 3.5840 (1.10) 68.7500 (1.19) 4.5000 (1.32) 2.7090 (62.98) 89;18 3999 1
bencode_rs.encode 145.0679 (0.50) 6.8933 (1.98) 1.5164 (3.09) 4.3330 (1.33) 60.3750 (1.04) 7.4590 (2.18) 2.5420 (59.09) 3136;32 10601 1
bcoding.encode 140.0668 (0.49) 7.1394 (2.05) 1.3146 (2.68) 6.6670 (2.05) 100.0000 (1.73) 7.0410 (2.06) 0.1660 (3.86) 410;1235 22494 1
better_bencode.encode 132.9986 (0.46) 7.5189 (2.16) 0.6240 (1.27) 7.0830 (2.18) 69.4170 (1.20) 7.4590 (2.18) 0.1260 (2.93) 754;3475 53571 1
fastbencode.encode 93.0336 (0.32) 10.7488 (3.09) 2.6568 (5.41) 8.2500 (2.54) 94.7080 (1.63) 9.2080 (2.69) 5.0420 (117.21) 7655;25 23977 1
bencodepy.encode 75.6976 (0.26) 13.2105 (3.80) 29.4086 (59.88) 8.3330 (2.56) 4,704.4170 (81.17) 9.2500 (2.71) 0.3340 (7.76) 1831;3331 51065 1

Test Environment: Python 3.11.13, MacBook Air M2, macOS 26.01, October 2025

Metadata

Release files for bencode.cy 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bencode.cy 1.2.2
File Size Uploaded
bencode_cy-1.2.2.tar.gz 81.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for bencode.cy 1.2.2
File
bencode_cy-1.2.2-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
bencode_cy-1.2.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.34+ x86-64, Linux glibc 2.17+ x86-64 Details
bencode_cy-1.2.2-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
bencode_cy-1.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64, Linux glibc 2.34+ x86-64 Details
bencode_cy-1.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64, Linux glibc 2.17+ x86-64 Details
bencode_cy-1.2.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
bencode_cy-1.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.34+ x86-64 Details
bencode_cy-1.2.2-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details
bencode_cy-1.2.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
bencode_cy-1.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.34+ x86-64 Details
bencode_cy-1.2.2-cp311-cp311-macosx_10_9_universal2.whl CPython 3.11 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) Details
bencode_cy-1.2.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
bencode_cy-1.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64, Linux glibc 2.34+ x86-64 Details
bencode_cy-1.2.2-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
bencode_cy-1.2.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
bencode_cy-1.2.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64, Linux glibc 2.34+ x86-64 Details
bencode_cy-1.2.2-cp39-cp39-macosx_10_9_universal2.whl CPython 3.9 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size: 3.0 MB

Release files / bencode_cy-1.2.2.tar.gz

Download URL bencode_cy-1.2.2.tar.gz
Size 81.3 kB
Tags Source
SHA-256 checksum
How to use checksums
43eb4cc53ba5bee249524e8c29da948678a1aabd410eae6c8752a9ba8d0950d1
BLAKE2b-256 checksum
How to use checksums
92c9a51d3e858fd8937670bee111ba3bd38aa97acd40070512e5c9f1424283d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp314-cp314t-win_amd64.whl

Download URL bencode_cy-1.2.2-cp314-cp314t-win_amd64.whl
Size 109.1 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
64e9ba3f2262ab9bb90b25056502e3ff5e869e779968fa3c159da5a00f8830e6
BLAKE2b-256 checksum
How to use checksums
0616a7a7e8f7618fe7684baeaae14713c7d14c7172b3c43bfd6283cb02b3d0c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 283.3 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
d26682ccd60e8ec97104833475ea6f02f834bb7f1ff575962b68bc972e30463d
BLAKE2b-256 checksum
How to use checksums
e3b9ba788c7244aa6dbaf56b75642947fafe68efbed511cfbdf476535602bfc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp314-cp314t-macosx_11_0_arm64.whl

Download URL bencode_cy-1.2.2-cp314-cp314t-macosx_11_0_arm64.whl
Size 106.0 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3b32e68cd7123232701e773d72bd940610b320c2ba72fe60aab56332e3b1e35b
BLAKE2b-256 checksum
How to use checksums
10dbb33c10994aeeeb5cf2bd60d7593fc2039e03dc1f12b150f669e956434a4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 254.1 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
a3fd7157280faf22bfd13e0db5a54300f87a4d2f6817f9673a5d5e53fc6139b7
BLAKE2b-256 checksum
How to use checksums
392bf21bdb6a56deb7ec7c54ea43d1833c0300e016c264c88490e127a7827e73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 255.7 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
aee1dcbe1e7cffadc8ee91e76f0c94deb73306421b59a28607ce5daac3d6ee43
BLAKE2b-256 checksum
How to use checksums
bc2b6ab9503f5043a11cbfe3d100ae4a68fff88015204a2a140ccc179ca9b479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp312-cp312-win_amd64.whl

Download URL bencode_cy-1.2.2-cp312-cp312-win_amd64.whl
Size 105.3 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
c282722ffbfda126556174d0f1cd5f1c4e9e96331ac34a8260955a8ee979d585
BLAKE2b-256 checksum
How to use checksums
9d00bf6ba4c6eab1408cae659537de1c19550e666ba042c5f7e991378129c6e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 257.8 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
b04525bcac62937d035f057399bb59738e5073809d87e945afb72933a2efcb42
BLAKE2b-256 checksum
How to use checksums
968c2176fd5727d068601f53f71e6e94f4d069402f1df235ef5d1affe428b5b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp312-cp312-macosx_15_0_arm64.whl

Download URL bencode_cy-1.2.2-cp312-cp312-macosx_15_0_arm64.whl
Size 104.5 kB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
970eb7cab92173e8b4f4679f33d1af72d1882b51f77cf42caa7970b1418c170c
BLAKE2b-256 checksum
How to use checksums
6dd0fe0fc960e2bfcc0eefb109a2e735316486dfdbd8028212cd66ac4ce35eea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp311-cp311-win_amd64.whl

Download URL bencode_cy-1.2.2-cp311-cp311-win_amd64.whl
Size 104.7 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
b5146c596973b7f59f1bc91d7b57ac421bfbb1370426924fd6424cbdd8674a6f
BLAKE2b-256 checksum
How to use checksums
cf4839c9bd13d9140309f12389f1478f002080996cef2ebf94a6eff5b23315d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 251.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
810835bc43c2b8ed1321cc28c658ec881f2995341db9f0aceba79ce69b879893
BLAKE2b-256 checksum
How to use checksums
be6842d60b15b6ae6ea5cbcf87ec761bf30b4b810033c5dff9bbcbbf4becb7ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp311-cp311-macosx_10_9_universal2.whl

Download URL bencode_cy-1.2.2-cp311-cp311-macosx_10_9_universal2.whl
Size 130.8 kB
Tags CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
b3eacd0929b1357d49991f60e89684c86522966c76d387abe09df9228814e7fc
BLAKE2b-256 checksum
How to use checksums
79166e245b48b7d0892ca90a76e93fefcc6a1e69ed41cb1bb7058d95602e68b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp310-cp310-win_amd64.whl

Download URL bencode_cy-1.2.2-cp310-cp310-win_amd64.whl
Size 104.8 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
4ec150d5fabec99845d53d1aeb747365ac38a903d45dad8e9c6e663dd30ce706
BLAKE2b-256 checksum
How to use checksums
29921a3d2a43bccc6b6fb7a1a7162b543233dd50b9965cf36bf9e0aa48a7d2b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 236.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
86f981b17876ba6c692624b0334ef5292faf18eb10281f2a8e74d3020bd6e664
BLAKE2b-256 checksum
How to use checksums
978fc9a361a998ca31d7dfb41e3a306badfd755d6df64acd42bac2ae67eb1fb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp310-cp310-macosx_11_0_arm64.whl

Download URL bencode_cy-1.2.2-cp310-cp310-macosx_11_0_arm64.whl
Size 104.1 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fd44d3dc4851e7d9fb9e2ec409294fd9e8473782ebbaeec078b02fc8777eba34
BLAKE2b-256 checksum
How to use checksums
555196d158177a34893ae2d603a65548be032556af67f60921ae888a7c34e01e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp39-cp39-win_amd64.whl

Download URL bencode_cy-1.2.2-cp39-cp39-win_amd64.whl
Size 104.8 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
59990540390968e2b1b5cec45e3b60e197e367ee895d81a13fd1f519a7017d29
BLAKE2b-256 checksum
How to use checksums
88c871d98a21a233b056b1e90fc724912265f2e9827fc8c75064cd09c70a4f35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl

Download URL bencode_cy-1.2.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_34_x86_64.whl
Size 235.8 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
1627e772305abe93f09eb59c5ddd8b39a867e7cbaf28827dae3471de9b446682
BLAKE2b-256 checksum
How to use checksums
87755fa72009bdde224cd3610c7f949a3eb4e1f9766f66881fe5de1ac630c649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / bencode_cy-1.2.2-cp39-cp39-macosx_10_9_universal2.whl

Download URL bencode_cy-1.2.2-cp39-cp39-macosx_10_9_universal2.whl
Size 130.4 kB
Tags CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
6fa2338fa9a7303df2a0f6b8c064761ada021b7224a4e86b58052f9d5955c395
BLAKE2b-256 checksum
How to use checksums
f8b2fea7ab167ff8618bd8823a1b1b150af9a84aa800b47a3ef8234589accb16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release history Release notifications | RSS feed

This release

1.2.2 This release

18 release files

1.0.1

6 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page