Skip to main content

A Python client for Substrate telemetry.

Project description

Substrate telemetry client

A Python client for Substrate's telemetry backend, providing real-time access to node data from chains like Polkadot and Kusama. It offers both synchronous and asynchronous interfaces.

Quick start

  1. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    
  2. Install the package in editable mode:

    pip install -e .
    
  3. Run the example script:

    python3 examples/basic_usage.py
    

Usage

This client can be used in two ways: synchronously or asynchronously.

TelemetryClient

The TelemetryClient provides a simple, blocking interface that runs network communication in a background thread.

import time
from substrate_telemetry_client import TelemetryClient, ChainGenesis

with TelemetryClient(chain=ChainGenesis.POLKADOT) as client:
    # Some time for data to arrive
    time.sleep(5)
    nodes = client.get_nodes()

    if nodes:
        print(nodes[0])

AsyncTelemetryClient

The AsyncTelemetryClient is designed for asyncio-based applications.

import asyncio
from substrate_telemetry_client import AsyncTelemetryClient, ChainGenesis

async def main():
    client = AsyncTelemetryClient(chain=ChainGenesis.KUSAMA)
    connect_task = asyncio.create_task(client.connect())
    # ... use client methods ...
    await client.disconnect()

For runnable examples demonstrating usage, please see the scripts in the examples/ directory.

Data structures

The client returns data in dataclasses like NodeInfo and ChainStats.

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

substrate_telemetry_client-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

substrate_telemetry_client-0.1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file substrate_telemetry_client-0.1.1.tar.gz.

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a06074acfc7a4786204ecaa0fceaef7d408f5610c10eb00d12bb052fb7f2ca47
MD5 0c2714432a6c6ac974b3bbe1347a5cd4
BLAKE2b-256 91a9aeec1ede28d22ba49ef9c551440b7f8222d2eed29e30a6df754a3125fbc6

See more details on using hashes here.

File details

Details for the file substrate_telemetry_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d01f77acc36717e114eedbd105e4879b1c249d496af7157a391f5d05aeabede
MD5 02d4a500d29aaad2f0630001f48707ee
BLAKE2b-256 306423fe7d19c26eec73235d8135b133dd9d852d4d436fd5fbf3e40e1c2909f0

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