Skip to main content

No project description provided

Project description

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 will be published as soon as we have a stable version with the above feature set. For now, you can build the package locally by first installing maturin with:

pipx install maturin

and then running following command:

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
    ./target/release/node-template --dev
    
  2. Running the python tests, which connect to the local node:
    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.

Project details


Download files

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

Source Distribution

subxtpy-0.1.0.tar.gz (67.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subxtpy-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file subxtpy-0.1.0.tar.gz.

File metadata

  • Download URL: subxtpy-0.1.0.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.5.1

File hashes

Hashes for subxtpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 acb77a758c337209702982bf21f767496832ccbb5b04fb94cf0c1a38062d55d2
MD5 fa8f2179e0aea39f0246a3de52aa9c94
BLAKE2b-256 d999dbdbf51aa2e94eac95d2e68bded82a9b454f5906ee5a8e914af498e5f5de

See more details on using hashes here.

File details

Details for the file subxtpy-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for subxtpy-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 523e96bd9a3aab7a9e84e1ec1e3dff3f5d74f27f259a0096f778bde013a9fc81
MD5 eaf2eed2c5718db09f53e1eae29ce80d
BLAKE2b-256 eb84b79e12eb5a70535f7aaa4b5a06f613c14553e677ce3b8230b1105833acba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page