scalecodec


Namescalecodec JSON
Version 1.2.11 PyPI version JSON
download
home_pagehttps://github.com/polkascan/py-scale-codec
SummaryPython SCALE Codec Library
upload_time2024-07-05 11:48:46
maintainerNone
docs_urlNone
authorStichting Polkascan (Polkascan Foundation)
requires_python<4,>=3.6
licenseNone
keywords scale codec polkascan polkadot substrate blockchain kusama
VCS
bugtrack_url
requirements base58 atomicwrites attrs coverage more-itertools pluggy pytest requests six mkdocs mkdocs-material mkdocs-autorefs mkdocstrings mkdocstrings
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python SCALE Codec

[![Build Status](https://img.shields.io/github/actions/workflow/status/polkascan/py-scale-codec/unittests.yml?branch=master)](https://github.com/polkascan/py-scale-codec/actions/workflows/unittests.yml?query=workflow%3A%22Run+unit+tests%22)
[![Latest Version](https://img.shields.io/pypi/v/scalecodec.svg)](https://pypi.org/project/scalecodec/) 
[![Supported Python versions](https://img.shields.io/pypi/pyversions/scalecodec.svg)](https://pypi.org/project/scalecodec/)
[![License](https://img.shields.io/pypi/l/scalecodec.svg)](https://github.com/polkascan/py-scale-codec/blob/master/LICENSE)


## Description
[Substrate](https://github.com/paritytech/substrate) uses a lightweight and efficient [encoding and decoding program](https://docs.substrate.io/reference/scale-codec/) 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 **S**imple **C**oncatenated **A**ggregate **L**ittle-**E**ndian.

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


## Installation
```bash
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](https://docs.substrate.io/reference/address-formats/) representation of an account. See also the [SS58 util functions](https://polkascan.github.io/py-scale-codec/utils/ss58.html)                                                                                                                                                                                                                                                                               | `"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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/polkascan/py-scale-codec",
    "name": "scalecodec",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.6",
    "maintainer_email": null,
    "keywords": "scale codec polkascan polkadot substrate blockchain kusama",
    "author": "Stichting Polkascan (Polkascan Foundation)",
    "author_email": "info@polkascan.org",
    "download_url": "https://files.pythonhosted.org/packages/bc/7c/703893e7a8751318517a3dd8c0c060b2c30ffa33f4ab5dd6a4ed483f7967/scalecodec-1.2.11.tar.gz",
    "platform": null,
    "description": "# Python SCALE Codec\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/polkascan/py-scale-codec/unittests.yml?branch=master)](https://github.com/polkascan/py-scale-codec/actions/workflows/unittests.yml?query=workflow%3A%22Run+unit+tests%22)\n[![Latest Version](https://img.shields.io/pypi/v/scalecodec.svg)](https://pypi.org/project/scalecodec/) \n[![Supported Python versions](https://img.shields.io/pypi/pyversions/scalecodec.svg)](https://pypi.org/project/scalecodec/)\n[![License](https://img.shields.io/pypi/l/scalecodec.svg)](https://github.com/polkascan/py-scale-codec/blob/master/LICENSE)\n\n\n## Description\n[Substrate](https://github.com/paritytech/substrate) uses a lightweight and efficient [encoding and decoding program](https://docs.substrate.io/reference/scale-codec/) 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 **S**imple **C**oncatenated **A**ggregate **L**ittle-**E**ndian.\n\n## Documentation\nhttps://polkascan.github.io/py-scale-codec/\n\n\n## Installation\n```bash\npip install scalecodec\n```\n\n## Examples of different types\n\n| Type                                                                         | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Example SCALE decoding value                                                | SCALE encoded value                                                             |\n|------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------|\n| `bool`                                                                       | Boolean values are encoded using the least significant bit of a single byte.                                                                                                                                                                                                                                                                                                                                                                                                         | `True`                                                                      | `0x01`                                                                          |\n| `u16`                                                                        | Basic integers are encoded using a fixed-width little-endian (LE) format.                                                                                                                                                                                                                                                                                                                                                                                                            | `42`                                                                        | `0x2a00`                                                                        |\n| `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`                                                                          |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `1`                                                                         | `0x04`                                                                          |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `42`                                                                        | `0xa8`                                                                          |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `69`                                                                        | `0x1501`                                                                        |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `100000000000000`                                                           | `0x0b00407a10f35a`                                                              |\n| `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`                                                  |\n| `BitVec`                                                                     | A sequence of bools, represented in a more space efficient bit format                                                                                                                                                                                                                                                                                                                                                                                                             | `0b00000010_01111101`                                                    | `0x287d02`                                                  |\n| `str`,`Bytes`, `String`                                                      | Strings are Vectors of bytes (`Vec<u8>`) containing a valid UTF8 sequence.                                                                                                                                                                                                                                                                                                                                                                                                           | `\"Test\"`                                                                    | `0x1054657374`                                                                  |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `b\"Test\"`                                                                   | `0x1054657374`                                                                  |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `[84, 101, 115, 116]`                                                       | `0x1054657374`                                                                  |\n| `[u8; 4]`                                                                    | Fixed sized array of in this case an `u8`                                                                                                                                                                                                                                                                                                                                                                                                                                            | `b\"babe\"`                                                                   | `0x62616265`                                                                    |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `\"0x62616265\"`                                                              | `0x62616265`                                                                    |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `[98, 97, 98, 101]`                                                         | `0x62616265`                                                                    |\n| `AccountId`                                                                  | An [SS58 formatted](https://docs.substrate.io/reference/address-formats/) representation of an account. See also the [SS58 util functions](https://polkascan.github.io/py-scale-codec/utils/ss58.html)                                                                                                                                                                                                                                                                               | `\"5GDyPHLVHcQYPTWfygtPY eogQjyZy7J9fsi4brPhgEFq4pcv\"`                       | `0xb80269ec500e458a630846b99105c397 ee574125823d6f4388e9c7572e115c05`           |\n| `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`                                                                        |\n|                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `{'Bool': True}`                                                            | `0x0101`                                                                        |\n| `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` |\n\n## License\nhttps://github.com/polkascan/py-scale-codec/blob/master/LICENSE\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python SCALE Codec Library",
    "version": "1.2.11",
    "project_urls": {
        "Homepage": "https://github.com/polkascan/py-scale-codec"
    },
    "split_keywords": [
        "scale",
        "codec",
        "polkascan",
        "polkadot",
        "substrate",
        "blockchain",
        "kusama"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bb602a903fa9ed3dfc842240da22969a25b16ea213ed3ee25b7ba8ae1cba20c7",
                "md5": "a6628fbc5f44420a3189e28b88e98920",
                "sha256": "d15c94965f617caa25096f83a45f5f73031d05e6ee08d6039969f0a64fc35de1"
            },
            "downloads": -1,
            "filename": "scalecodec-1.2.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a6628fbc5f44420a3189e28b88e98920",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.6",
            "size": 99164,
            "upload_time": "2024-07-05T11:48:42",
            "upload_time_iso_8601": "2024-07-05T11:48:42.777908Z",
            "url": "https://files.pythonhosted.org/packages/bb/60/2a903fa9ed3dfc842240da22969a25b16ea213ed3ee25b7ba8ae1cba20c7/scalecodec-1.2.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc7c703893e7a8751318517a3dd8c0c060b2c30ffa33f4ab5dd6a4ed483f7967",
                "md5": "51d97324b91a4f609abd42bd55b97b0a",
                "sha256": "99a2cdbfccdcaf22bd86b86da55a730a2855514ad2309faef4a4a93ac6cbeb8d"
            },
            "downloads": -1,
            "filename": "scalecodec-1.2.11.tar.gz",
            "has_sig": false,
            "md5_digest": "51d97324b91a4f609abd42bd55b97b0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.6",
            "size": 150260,
            "upload_time": "2024-07-05T11:48:46",
            "upload_time_iso_8601": "2024-07-05T11:48:46.146599Z",
            "url": "https://files.pythonhosted.org/packages/bc/7c/703893e7a8751318517a3dd8c0c060b2c30ffa33f4ab5dd6a4ed483f7967/scalecodec-1.2.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-05 11:48:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "polkascan",
    "github_project": "py-scale-codec",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "base58",
            "specs": [
                [
                    "==",
                    "2.0.1"
                ]
            ]
        },
        {
            "name": "atomicwrites",
            "specs": [
                [
                    "~=",
                    "1.4.0"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    "~=",
                    "20.3.0"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "5.3"
                ]
            ]
        },
        {
            "name": "more-itertools",
            "specs": [
                [
                    "~=",
                    "8.6.0"
                ]
            ]
        },
        {
            "name": "pluggy",
            "specs": [
                [
                    "==",
                    "0.13.1"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "6.1.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.24.0"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.15.0"
                ]
            ]
        },
        {
            "name": "mkdocs",
            "specs": []
        },
        {
            "name": "mkdocs-material",
            "specs": []
        },
        {
            "name": "mkdocs-autorefs",
            "specs": []
        },
        {
            "name": "mkdocstrings",
            "specs": []
        },
        {
            "name": "mkdocstrings",
            "specs": []
        }
    ],
    "lcname": "scalecodec"
}
        
Elapsed time: 3.14410s