Skip to main content

Python SCALE Codec Library for Polymesh

Project description

This project is forked from https://github.com/polkascan/py-scale-codec

Python Polymath SCALE Codec

Latest Version Supported Python versions

Python Polymath SCALE Codec Library

Description

Most of the data that the Substrate RPCs output is encoded with the SCALE Codec. This codec is used by the Substrate nodes' internal runtime. In order to get to meaningful data this data will need to be decoded. The Python SCALE Codec Library will specialize in this task.

Documentation

https://polkascan.github.io/py-scale-codec/

Installation

pip install polymath-scalecodec

Examples

Decode a SCALE-encoded Compact<Balance>

RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))
RuntimeConfiguration().update_type_registry(load_type_registry_preset("kusama"))
obj = ScaleDecoder.get_decoder_class('Compact<Balance>', ScaleBytes("0x130080cd103d71bc22"))
obj.decode()
print(obj.value)

Add custom types to type registry

RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))

custom_types = {
    "types": {
        "MyCustomType": "u32",
        "CustomNextAuthority": {
          "type": "struct",
          "type_mapping": [
             ["AuthorityId", "AuthorityId"],
             ["weight", "AuthorityWeight"]
          ]
        }
    }
}

RuntimeConfiguration().update_type_registry(custom_types)

Or from a custom JSON file

RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))
RuntimeConfiguration().update_type_registry(load_type_registry_file("/path/to/type_registry.json"))

License

https://github.com/PolymathNetwork/py-scale-codec/blob/master/LICENSE

Project details


Download files

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

Files for polymath-scalecodec, version 0.3.17b1
Filename, size File type Python version Upload date Hashes
Filename, size polymath_scalecodec-0.3.17b1-py3-none-any.whl (52.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size polymath-scalecodec-0.3.17b1.tar.gz (213.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page