Python SDK

Data Engine's live data feeds can be accessed through the Relayer using the official Python SDK.

Overview

The general process to set-up and other do's & don'ts while connecting to the relayer remain the same as discussed in the WebSockets section.

Quick Start

1. Install

First, install Relayer-Python-SDK to start things up.

$ pip install relayer-python-sdk

Note - It is recommended to set-up your own virtual environment for the project through venv or poetry.

2. Set-Up

Now, set-up the SDK with the relevant imports and feedIDs.

main.py
import asyncio
from relayer_python_sdk.ws import RelayerWS
from relayer_python_sdk import events

feedIDs = 
ws = 

3. Consume Events

After initializing the SDK with the relevant parameters. You can now start consuming the events through the relevant event handlers. The main function here is the asyncio runner that starts the Relayer Connection and then closes the connection after a deadline.

main.py
@ws.on_data_event
async def on_data_event(event: events.DataFeed):
    print("Data Feed Event:", event)


@ws.on_info_event
async def on_info_event(event: events.SubscriptionMsg):
    print("Info event:", event)


async def main():
    sub_task = asyncio.create_task(ws.connect())

    await asyncio.sleep(10)
    await ws.close()

    await sub_task


if __name__ == "__main__":
    asyncio.run(main())

Last updated