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.4.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.4-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.4.tar.gz.

File metadata

  • Download URL: pypolkadot-0.2.4.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.4.tar.gz
Algorithm Hash digest
SHA256 4e95e62a87837c512e686afcda964473408c4895b8edf16022bfe879c1c068a9
MD5 0e8d59522fbe5480204cc569c57e5d5c
BLAKE2b-256 5fca83356c80d9302ae0db934d42894f4e1d9f4b4be83eca76ebcfd7492ee1ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pypolkadot-0.2.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dc7087d4032f4e64e7c1928ecca05fc1fa124a29514dad0f390c5173fd191751
MD5 0abdb483f85f110a9100fb88c8b08e1d
BLAKE2b-256 f4480722930960b3b141137e2e026ea2248bfb21f355954518b3d60e071ed2d8

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