Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpler-rlp-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpler_rlp-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for simpler-rlp-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6274b72724232141229074174c76201dfa3fcbae7518ac3c8f7ff6a3434eb1bf
MD5 d74fdb9a0db2aaef17e7edf4c3c7aeb1
BLAKE2b-256 18eec5011f2e2e628616f1546ce4fc82a887548f5459518afe829f64577053c9

See more details on using hashes here.

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

Hashes for simpler_rlp-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d82a95ec82ded58ec6d3c89275e92aee911f94954d70d6bf14943ec4bfd25473
MD5 ebf4b0deed99abcf09a52a4204a418f1
BLAKE2b-256 275eedb1ecdcfc0e8e67696c622e26c880c3206aea0085ebe2ba00e82e86d95e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page