Skip to main content

Python Substrate Interface

Build Status Latest Version Supported Python versions License

Description

This library specializes in interfacing with a Substrate node; querying storage, composing extrinsics, SCALE encoding/decoding and providing additional convenience methods to deal with the features and metadata of the Substrate runtime.

Documentation

Installation

Requires CPython 3.11 or newer. The test matrix covers 3.11 through 3.15.

python -m pip install substrate-interface

Python 3.15 may need to build native dependencies from source. Install the Rust toolchain and enable PyO3's stable ABI when no compatible wheels are available.

PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 python -m pip install substrate-interface

Initialization

Using embedded light client

substrate = SubstrateInterface(chainspec="polkadot_asset_hub", relay_chainspecs=["polkadot"])

Using node RPC endpoint

substrate = SubstrateInterface(url="ws://127.0.0.1:9944")

After connecting certain properties like ss58_format will be determined automatically by querying the RPC node. At the moment this will work for most MetadataV14 and above runtimes like Polkadot, Kusama, Acala, Moonbeam. For older or runtimes under development the ss58_format (default 42) and other properties should be set manually.

Quick usage

Balance information of an account

result = substrate.query('System', 'Account', ['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T'])
print(result.value['data']['free']) # 635278638077956496

Create balance transfer extrinsic

call = substrate.compose_call(
    call_module='Balances',
    call_function='transfer',
    call_params={
        'dest': '5E9oDs9PjpsBbxXxRE9uMaZZhnBAV38n2ouLB28oecBDdeQo',
        'value': 1 * 10**12
    }
)

keypair = Keypair.create_from_uri('//Alice')
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)

receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)

print(f"Extrinsic '{receipt.extrinsic_hash}' sent and included in block '{receipt.block_hash}'")

Running tests

Install the test dependencies with python -m pip install -e '.[test]' and run python -m pytest. To include tests that need live RPC endpoints, run RUN_LIVE_TESTS=1 python -m pytest. The endpoint overrides are listed in test/settings.py.

Contact and Support

For questions, please see the Substrate StackExchange or Github Discussions.

License

https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE

Metadata

Release files for substrate-interface 1.9.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 substrate-interface 1.9.0
File Size Uploaded Provenance Actions
substrate_interface-1.9.0.tar.gz 1.5 MB Without provenance Details for substrate_interface-1.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for substrate-interface 1.9.0
File Interpreter ABI Platform Actions
substrate_interface-1.9.0-py3-none-any.whl Python 3 none any Details for substrate_interface-1.9.0-py3-none-any.whl

Total release size: 2.9 MB

Release files / substrate_interface-1.9.0.tar.gz

Download URL substrate_interface-1.9.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
1c82bffd9671d7c27a12b54d56a742aa4ae8787ac21240e07e42008752a0f9c2
BLAKE2b-256 checksum
How to use checksums
60c50e6eb1333397f7273cbc284c90fde8c42d2db04f9166582a620d39ef2ff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / substrate_interface-1.9.0-py3-none-any.whl

Download URL substrate_interface-1.9.0-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
13d424862b9073bdcba0d620a71f537b08c1b9a3ee89c3b6049413c14b47fdf8
BLAKE2b-256 checksum
How to use checksums
c346ab19f48604991858df56a667a49a08973f4ac7e11a71bea4d1af500c257c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for substrate-interface 1.9.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.9.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