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.2.tar.gz (8.7 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.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d050fbc5058705dbb2c27a6e716b427cd71e0f017e093acdd524d4ac9b1889a4
MD5 e1e2e27f1fa5b64175e6911f5c9d4470
BLAKE2b-256 b4d92c132e261c058e585fe2f33bf1360c1c2ca627dbc00013184321e63db141

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for substrate_telemetry_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b74728a1ffb4d6c2d151b47075ba8da06042fdf6d87bb1670f62079188821af4
MD5 9ea8b365adf4ff50892dcf77c14a8805
BLAKE2b-256 0401c87e0a11c151752957d9d852d383cbe8a03fc5c810f8baf6defcf36e59e8

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