Python Client

A python package is available to ease integration into python-based projects. To install locally:

Setup Guide

Prerequisites

  • Git

  • Rust 1.84.0 or later

  • Python 3.9 or above

Install the package

pip install git+https://github.com/propeller-heads/tycho-indexer.git#subdirectory=tycho-client-py

Understanding and using the Python Client

The Python client is a Python wrapper around our Rust Client that enables interaction with the Tycho Indexer. It provides two main functionalities:

  • Streaming Client: Python wrapper around Rust Client for real-time data streaming

  • RPC Client: Pure Python implementation for querying Tycho RPC data

Streaming Implementation

The TychoStream class:

  1. Locates the Rust binary (tycho-client-cli)

  2. Spawns the binary as a subprocess

  3. Configures it with parameters like URL, authentication, exchanges, and filters

  4. Implements an async iterator pattern that:

    • Reads JSON output from the binary's stdout

    • Parses messages into Pydantic models

    • Handles errors and process termination

Here's one example on how to use it:

RPC Client Implementation

The TychoRPCClient class:

  • Makes HTTP requests to the Tycho RPC server

  • Serializes Python objects to JSON

  • Deserializes JSON responses to typed Pydantic models

  • Handles blockchain-specific data types like HexBytes

Here's one example on how to use it to fetch tokens information (available at Tycho RPC endpoint):

Last updated