Skip to main content

subxtpy · build Documentation

subxtpy is a Python wrapper for the subxt library. This library leverages the functionality provided by the subxt library to offer a convenient and efficient way to communicate with Substrate-based blockchains in Python.

Features

Feature Description Supported
Submit Extrinsics Submit transactions (extrinsics) to the blockchain. ✅
Read Storage Values Read and iterate over storage values on the blockchain. ✅
Read Constants Fetch constants defined in the runtime metadata. ✅
Call Runtime APIs Call runtime APIs and retrieve their results. ✅
Dynamic Types Use dynamic types based on metadata for more flexible interactions. ✅
Subscribe to Blocks, events Subscribe to new blocks and read the extrinsics and events. ⏳ (Upcoming)

Usage

Installation

The package has been published on pypi and can be installed by running:

pip install subxtpy

Local Testing

To build the library locally, maturin needs to be installed. The following command will build the package locally:

maturin develop

Downloading Metadata from a Substrate Node

Use the subxt-cli tool to download the metadata for your target runtime from a node.

  1. Install:
cargo install subxt-cli
  1. Save the encoded metadata to a file:
subxt metadata -f bytes > artifacts/metadata.scale

This defaults to querying the metadata of a locally running node on the default http://localhost:9933/. If querying a different node, the metadata command accepts a --url argument.

Example Usage

Here is an example of how to use subxtpy to interact with a Substrate-based blockchain:

import asyncio
from subxtpy import SubxtClient, Keypair

async def main():
    client = await SubxtClient.from_url("ws://127.0.0.1:9944")

    # Read a storage value
    value = await client.storage("System", "Account",
                                 ["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"])
    print(value)

    # Fetch a constant
    constant_value = await client.constant("Balances", "ExistentialDeposit")
    print(constant_value)

    # Call a runtime API
    api_result = await client.runtime_api_call("AccountNonceApi", "account_nonce",
                                               ["e5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a"])
    print(api_result)

    # Sign and submit a transaction
    from_keypair = Keypair.from_secret_key("e5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a")

    remark_payload = ["Hello"]
    transfer_tx_hash = await client.sign_and_submit(from_keypair, "System", "remark", remark_payload)
    print("Remark tx hash:", transfer_tx_hash)

asyncio.run(main())

Subxtpy Documentation

For more details regarding utilizing subxtpy, please visit the documentation.

Testing

We wrote some tests by following the examples provided in the official subxt repo. These tests can be run by running:

  1. Node template locally:
    cargo build --package minimal-template-node --release
    ./target/release/minimal-template-node --dev
    
    # docker version:
    docker build . -t polkadot-sdk-minimal-template
    docker run -p 9944:9944 --rm polkadot-sdk-minimal-template --dev --rpc-external
    
  2. Running the python tests, which connect to the local node:
    pip install -r requirements.txt
    pytest
    

Contributing

Contributions to subxtpy are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

Real World Usage

We will be providing guides for various real-world use cases here.

License

The entire code within this repository is licensed under the Apache-2.0 license. See the LICENSE file for more details.

Metadata

Release files for subxtpy 0.2.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 subxtpy 0.2.0
File Size Uploaded Provenance
subxtpy-0.2.0.tar.gz 70.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for subxtpy 0.2.0
File Interpreter ABI Platform
subxtpy-0.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 2.0 MB

Release files / subxtpy-0.2.0.tar.gz

Download URL subxtpy-0.2.0.tar.gz
Size 70.3 kB
Tags Source
SHA-256 checksum
How to use checksums
74b699a5fb85d7e55d69bc4d01a6365cc0d745126c4bdff916c3646af93d909d
BLAKE2b-256 checksum
How to use checksums
7abde3bb3452b700f6f22189e5923302016837277808a3cabc47e7217d5cf140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / subxtpy-0.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL subxtpy-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 2.0 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c492c114ce51b6b464929f93efca28bdc9b984cc1489f62502e139d4ba1b9c1b
BLAKE2b-256 checksum
How to use checksums
fc2123c9db4144f47e0ed9c14ebab85a30904bf25f4c6f028ba2f056190ce7f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Security for subxtpy 0.2.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

0.2.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