Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Why yet another bencode package in python?
because I need a bencode library:
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.bencode2-${version}-py3-none-any.whl
wheel on pypi.pip install bencode2
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'
bencode type | python type |
---|---|
integer | int |
string | bytes |
array | list |
directory | dict |
bencode have 4 native types, integer, string, array and directory.
This package will decode integer to int
, array to list
and
directory 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
.
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 | directory |
types.MaapingProxy | directory |
dataclasses | directory |
bencode2 have a free threading wheel on pypi, build with GIL disabled.
When encoding or decoding, it will not acquire GIL, 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.
FAQs
A fast and correct bencode serialize/deserialize library
We found that bencode2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.