Skip to main content

RLP (Recursive Length Prefix) - Encode and decode data structures

Project description

Simple RLP (Recursive Length Prefix)

Encode the and decode data structures simple and fast

This module is a alternative to official Ethereum pyrlp.

The pyrlp needs 5 dependencies. This alternative is write in pure python and don't have any dependencies. Recommended use for projects that don't need the Ethereum tools. If you already uses the Ethereum tools uses the pyrlp.

Features:

  • Very simple usage to encode and decode lists of data
  • Very fast to encode
  • Auto serialize python objects (check supported types)
  • Templates to convert bytes in decoded objects
  • No dependencies

Installation:

pip install simple-rlp 

Usage:

Encode:
>>> import rlp
>>> my_list = ['python', 'rlp', 255]
>>> rlp.encode(my_list)
b'\xcd\x86python\x83rlp\x81\xff'
Decode:
>>> import rlp
>>> my_list_encoded = b'\xcd\x86python\x83rlp\x81\xff'
>>> rlp.decode(my_list_encoded)
[b'python', b'rlp', b'\xff']

Use templates to decode and convert the bytes to python objects

Supported types:
  • Signed integer
  • Unsigned integer
  • Bool
  • Float
  • String
rlp.converters.UInteger # Signed integer
rlp.converters.SInteger # Unsigned integer
rlp.converters.Bool # Bool
rlp.converters.Float # Float
rlp.converters.String # String

Signed and unsigned integer uses by default big-endian order. If you need to use little-endian edit the static attribute:

LittleEndianUInt = rlp.converters.UInteger
LittleEndianUInt.byteorder =  'little'

String uses UTF-8 encoding by default if you need to use another then:

ASCIIString = rlp.converters.String
ASCIIString.encoding =  'ascii'
Template Usage:
>>> from rlp.converters import *
>>> import rlp

>>> my_list = ['rlp', 1024, 3.14159, True, b'\x08']
>>> my_list_template = [String, UInteger, Float, Bool, None]
>>> my_list_encoded = rlp.encode(my_list)
>>> rlp.decode(my_list_encoded, template=my_list_template)
['rlp', 1024, 3.141590118408203, True, b'\x08']

Note: Put None object to do nothing in template.

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

simple-rlp-0.1.3.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file simple-rlp-0.1.3.tar.gz.

File metadata

  • Download URL: simple-rlp-0.1.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for simple-rlp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2df1d2b769f0a0177d26231ab8be16e65e3546b17bb0a9a490efd3517c082876
MD5 8345b03e053922becc507b6568a5a739
BLAKE2b-256 b6b5d379d077e0c38c2b37c64dedfaef16099299e401f6323fc170d16d6c7d43

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