Metadata-Version: 2.4
Name: substrate-telemetry-client
Version: 0.1.1
Summary: A Python client for Substrate telemetry.
Project-URL: Homepage, https://github.com/w3f/substrate-telemetry-client-py
Author-email: W3F SecOps Team <secops@web3.foundation>
License: MIT License
        
        Copyright (c) 2024 Web3 Foundation
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Requires-Dist: websockets>=10.0
Description-Content-Type: text/markdown

# Substrate telemetry client

A Python client for [Substrate's telemetry backend](https://github.com/paritytech/substrate-telemetry), 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:**
    ```bash
    python3 -m venv venv
    source venv/bin/activate
    ```

2.  **Install the package in editable mode:**
    ```bash
    pip install -e .
    ```

3.  **Run the example script:**
    ```bash
    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.

```python
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.

```python
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`.
