RLP (Recursive Length Prefix) - Encode and decode data structures
Project description
Simple RLP (Recursive Length Prefix)
Note
This is a copy of https://github.com/SamuelHaidu/simple-rlp with a fix to resolve conflicting directory names with https://github.com/ethereum/pyrlp
Efficiently encode and decode data structures with minimal dependencies
This module provides an alternative to the official Ethereum pyrlp library.
While pyrlp requires 5 dependencies, this alternative is written in pure Python and has no dependencies. It is recommended for projects that do not require the full suite of Ethereum tools. If your project already uses Ethereum tools, consider using pyrlp instead.
Features:
- Straightforward encoding and decoding of lists containing various data types
- Fast encoding process
- Automatic serialization of Python objects (refer to supported types below)
- Templates for converting bytes into decoded objects
- Dependency-free implementation
Installation:
pip install simpler-rlp
Usage:
Encoding:
>> > import simpler_rlp
>> > my_list = ['python', 'rlp', 255]
>> > simpler_rlp.encode(my_list)
b'\xcd\x86python\x83rlp\x81\xff'
Decoding:
>> > import simpler_rlp
>> > my_list_encoded = b'\xcd\x86python\x83rlp\x81\xff'
>> > simpler_rlp.decode(my_list_encoded)
[b'python', b'rlp', b'\xff']
Use templates to decode and convert bytes to Python objects
Supported Types:
- Signed integer
- Unsigned integer
- Boolean
- Float
- String
rlp.converters.UInteger # Unsigned integer
rlp.converters.SInteger # Signed integer
rlp.converters.Bool # Boolean
rlp.converters.Float # Float
rlp.converters.String # String
Both signed and unsigned integers use big-endian byte order by default. To use little-endian, modify the static attribute:
LittleEndianUInt = rlp.converters.UInteger
LittleEndianUInt.byteorder = 'little'
String uses UTF-8 encoding by default. To use a different encoding, modify the static attribute:
ASCIIString = rlp.converters.String
ASCIIString.encoding = 'ascii'
Template Usage:
>> > from simpler_rlp.converters import *
>> > import simpler_rlp
>> > my_list = ['rlp', 1024, 3.14159, True, b'\x08']
>> > my_list_template = [String, UInteger, Float, Bool, None]
>> > my_list_encoded = simpler_rlp.encode(my_list)
>> > simpler_rlp.decode(my_list_encoded, template=my_list_template)
['rlp', 1024, 3.141590118408203, True, b'\x08']
Note: Use a None object in the template to leave the corresponding element unchanged.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simpler-rlp-0.0.1.tar.gz.
File metadata
- Download URL: simpler-rlp-0.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6274b72724232141229074174c76201dfa3fcbae7518ac3c8f7ff6a3434eb1bf
|
|
| MD5 |
d74fdb9a0db2aaef17e7edf4c3c7aeb1
|
|
| BLAKE2b-256 |
18eec5011f2e2e628616f1546ce4fc82a887548f5459518afe829f64577053c9
|
File details
Details for the file simpler_rlp-0.0.1-py3-none-any.whl.
File metadata
- Download URL: simpler_rlp-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d82a95ec82ded58ec6d3c89275e92aee911f94954d70d6bf14943ec4bfd25473
|
|
| MD5 |
ebf4b0deed99abcf09a52a4204a418f1
|
|
| BLAKE2b-256 |
275eedb1ecdcfc0e8e67696c622e26c880c3206aea0085ebe2ba00e82e86d95e
|