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 Polkadot blockchains 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 Polkadot mainnet (embedded light client)
client = LightClient()

# 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 Polkadot mainnet
LightClient(testnet=True) Connect to Polkadot mainnet
LightClient.from_chain_spec(json) Connect with custom chain spec
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.1.tar.gz (570.9 kB 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.1-cp312-cp312-macosx_11_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pypolkadot-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c38590b8e301a56a4689148eee416a4f14b3619cd5bec9cbae51be171f600ff0
MD5 0ab70610265071cafb509434cda4f8f5
BLAKE2b-256 2660cff58810a8be953b80efd12a4a4295901f4e43d225d227604f9688dcc6a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pypolkadot-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8dd0c1a9df090f74499fb782b3f489d78809a61f0b3ff89abd815a64d9e10b62
MD5 7679cab1dfc1638deefad0cbaf8bd845
BLAKE2b-256 cbafbf097aeeefb236b08f32214d76edcebf7e16b5ae28d9d217df84f4fc6c02

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