Git Product home page Git Product logo

simple-rlp's Introduction

Simple RLP (Recursive Length Prefix)

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 simple-rlp 

Usage:

Encoding:
>>> import rlp
>>> my_list = ['python', 'rlp', 255]
>>> rlp.encode(my_list)
b'\xcd\x86python\x83rlp\x81\xff'
Decoding:
>>> 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 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 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: Use a None object in the template to leave the corresponding element unchanged.

simple-rlp's People

Contributors

samuelhaidu avatar shaidu-gif avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

simple-rlp's Issues

the modified MIT licence and Guix (FSF)

i'm packaging trezor stuff for Guix (a linux distro). it is an FSF free software fundamentalist distro, which means that "anything restricting the basic freedoms make licenses non-free", which applies to your last sentence "This software cannot be used by state organizations.".

now, i fully agree with you... but due to this i cannot update trezor support in Guix (or at least not easily; i'd need to weed out the tests that require this lib).

and arguably, it's also too broad; i.e. it includes schools run with government money, and also not very clear where the line is between state and non-state organizations.

in these lights, would you be willing to revert to vanilla MIT?

consider tagging the git repo

it helps the packagers, who don't want to trust/rely on pypi.org.

PGP signing the tags adds some extra geek value... :)

rlp directory name conflicts with the full pyrlp package

Not sure if this is fixable at this point, but the decision to call this directory rlp is quite destructive to users who are also using pyrlp in parallel (not by their own design necessarily... just because of dependencies in other packages).

When pip installs this package, it overwrites the contents of pyrlp in /site-packages. Huge headache to fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.