Skip to main content

Python light client for Polkadot/Substrate via smoldot

Project description

pypolkadot

Experimental Python light client for Polkadot/Substrate via smoldot.

Connect to Asset Hub (Polkadot, Kusama, Paseo) trustlessly - no full node, no RPC provider needed.

This is a feasibility demonstrator to integrate the functionality in https://github.com/JAMdotTech/py-polkadot-sdk.

Installation

pip install pypolkadot

Quick Start

from pypolkadot import LightClient

# Connect to Asset Hub (default: Polkadot)
client = LightClient()
client = LightClient(network="kusama")   # Asset Hub Kusama
client = LightClient(network="paseo")    # Paseo Asset Hub (testnet)

# Query storage
total = client.storage("Balances", "TotalIssuance")
print(f"Total issuance: {total}")

# Get events
for event in client.events(pallet="System"):
    print(f"{event.pallet}.{event.name}")

# Subscribe to blocks
for block in client.subscribe_finalized():
    print(f"Block #{block.number}: {block.hash}")

Features

  • Verifies proofs cryptographically, no RPC trust required
  • Light client runs in-process, no external dependencies
  • Query any storage/events without codegen
  • Simple Python API, no async/await required

API

Method Description
LightClient() Connect to Asset Hub Polkadot
LightClient(network="kusama") Connect to Asset Hub Kusama
LightClient(network="paseo") Connect to Paseo Asset Hub (testnet)
LightClient.from_chain_spec(json) Connect with custom chain spec
client.get_finalized_block() Get latest finalized block
client.storage(pallet, entry, keys) Query storage
client.events(block_hash, pallet, name) Get/filter events
client.submit(signed_hex) Submit pre-signed extrinsic
client.subscribe_finalized() Stream finalized blocks

Development

# Setup
uv venv && source .venv/bin/activate
pip install maturin

# Build
maturin develop

# Test
python tests/test_storage.py

License

GPL-3.0 as intended.

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

pypolkadot-0.2.5.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

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

pypolkadot-0.2.5-cp312-cp312-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file pypolkadot-0.2.5.tar.gz.

File metadata

  • Download URL: pypolkadot-0.2.5.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pypolkadot-0.2.5.tar.gz
Algorithm Hash digest
SHA256 f53e56e7c4e875f090bd8670ba3740968c3093999f472eb6c195fdbb40ad0b31
MD5 a37590beb2fc9f48ec6a9eea37ddaff3
BLAKE2b-256 dc31abeb81086d051c17322e42b2285b0364174325377b7f7c1de23d848fdbe6

See more details on using hashes here.

File details

Details for the file pypolkadot-0.2.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypolkadot-0.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b62ee068ecc5b7c29cd88d9eae6a9972f4cb080c1337262eb87cf534eafc1cf
MD5 bce1e41770fbede3cae1b9c106c96a97
BLAKE2b-256 0e0119bb7bbbd2c14293e60ba10b25785ab4f6246d5f3f4a2743f2425199cec5

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