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.0.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.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fedb0a9f6011253f287fbb62950d4b38627828fcce302c9e90f0831554c0d29b
MD5 dc26a70ba380cf2c21a3bcdf8826c36c
BLAKE2b-256 dd48f3ccddd7bbd05d54adcd4a65010b418437837c05b38d147d4628a55db1d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1088f91bb055dc205e7ad76cc66a8b42285df9090ee94c5b37b3a34dd7f3f634
MD5 1c1e956f29adf26de6edc99df2886644
BLAKE2b-256 c8f141b7a412dd60cd1dc0d10e6a58790d09837400f27aaea63801107f217052

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