Skip to main content

Python SCALE Codec

Build Status Latest Version Supported Python versions License

Description

Substrate uses a lightweight and efficient encoding and decoding program to optimize how data is sent and received over the network. The program used to serialize and deserialize data is called the SCALE codec, with SCALE being an acronym for Simple Concatenated Aggregate Little-Endian.

Documentation

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

Installation

pip install scalecodec

Examples of different types

Type Description Example SCALE decoding value SCALE encoded value
bool Boolean values are encoded using the least significant bit of a single byte. True 0x01
u16 Basic integers are encoded using a fixed-width little-endian (LE) format. 42 0x2a00
Compact A "compact" or general integer encoding is sufficient for encoding large integers (up to 2**536) and is more efficient at encoding most values than the fixed-width version. (Though for single-byte values, the fixed-width integer is never worse.) 0 0x00
1 0x04
42 0xa8
69 0x1501
100000000000000 0x0b00407a10f35a
Vec A collection of same-typed values is encoded, prefixed with a compact encoding of the number of items, followed by each item's encoding concatenated in turn. [4, 8, 15, 16, 23, 42] 0x18040008000f00100017002a00
BitVec A sequence of bools, represented in a more space efficient bit format 0b00000010_01111101 0x287d02
str,Bytes, String Strings are Vectors of bytes (Vec<u8>) containing a valid UTF8 sequence. "Test" 0x1054657374
b"Test" 0x1054657374
[84, 101, 115, 116] 0x1054657374
[u8; 4] Fixed sized array of in this case an u8 b"babe" 0x62616265
"0x62616265" 0x62616265
[98, 97, 98, 101] 0x62616265
AccountId An SS58 formatted representation of an account. See also the SS58 util functions "5GDyPHLVHcQYPTWfygtPY eogQjyZy7J9fsi4brPhgEFq4pcv" 0xb80269ec500e458a630846b99105c397 ee574125823d6f4388e9c7572e115c05
Enum Example: enum IntOrBool { Int(u8), Bool(bool),} A fixed number of variants, each mutually exclusive and potentially implying a further value or series of values. Encoded as the first byte identifying the index of the variant that the value is. Any further bytes are used to encode any data that the variant implies. Thus, no more than 256 variants are supported. {'Int': 8} 0x002a
{'Bool': True} 0x0101
Struct Example: struct Motion { pub votes: Vec<AccountId>, pub id: u32 } For structures, the values are named, but that is irrelevant for the encoding (names are ignored - only order matters). All containers store elements consecutively. The order of the elements is not fixed, depends on the container, and cannot be relied on at decoding. This implicitly means that decoding some byte-array into a specified structure that enforces an order and then re-encoding it could result in a different byte array than the original that was decoded. {"votes": ["5GDyPHLVHcQYPTWfygtPYeo gQjyZy7J9fsi4brPhgEFq4pcv"], "id": 4} 0x04b80269ec500e458a630846b99105c397ee57 4125823d6f4388e9c7572e115c0504000000

License

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

Metadata

Release files for scalecodec 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scalecodec 1.3.0
File Size Uploaded Provenance Actions
scalecodec-1.3.0.tar.gz 153.6 kB Without provenance Details for scalecodec-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scalecodec 1.3.0
File Interpreter ABI Platform Actions
scalecodec-1.3.0-py3-none-any.whl Python 3 none any Details for scalecodec-1.3.0-py3-none-any.whl

Total release size: 253.7 kB

Release files / scalecodec-1.3.0.tar.gz

Download URL scalecodec-1.3.0.tar.gz
Size 153.6 kB
Tags Source
SHA-256 checksum
How to use checksums
53092f2759298bd21d911dd4112ea3d87434a6818032da2278e1f4211cd90705
BLAKE2b-256 checksum
How to use checksums
fa5faf4cce0a3f6357ca1dc6afbf0d02c2636f4dec58f2f2d46b688a95ede36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / scalecodec-1.3.0-py3-none-any.whl

Download URL scalecodec-1.3.0-py3-none-any.whl
Size 100.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8481ac9284c5891d83f13309c45ce51764c9981487b2f39ecd3bbe8689bc6c7b
BLAKE2b-256 checksum
How to use checksums
031a340fa876cce43faf4e16863f7f8d757775f57ca7fcf687f327caf8443032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for scalecodec 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page