Skip to content
Data > Clients

Python

Setup

The python library files are available upon request - please contact support@3forge.com to receive the latest version of the library.
This library requires the chardet library, and it can be installed via pip: pip install chardet.

Overview

The python library provides an interface identical to Java and can be easily configured.

Example - Python Code

from com.f1.ami.client import AmiClient
from com.f1.ami.listener import AmiClientListenerInterface
from com.f1.utils.options import Options

class TestClient(AmiClientListenerInterface):
    "A script demonstrating how this client can be used to connect to AMI"
    def __init__(self) -> None:
        super().__init__()

        ad = AmiClient()
        options = Options.ENABLE_SEND_SEQNUM + Options.ENABLE_SEND_TIMESTAMPS
        ad.addListener(self)

        # ad.setDebugMessages()

        # Connecting to the AMI instance, replace with appropriate connection parameters
        ad.start("127.0.0.1", 3289, "demo", options)

        # Sending a row of data to the table 'Sample'
        ad.startObjectMessage("Sample")
        ad.addMessageParamString("Symbol", "GBP")
        ad.addMessageParamFloat("Quantity", 11.0)
        ad.sendMessageAndFlush()

        # print(ad.getOutputBuffer())

        ad.close()

    def onMessageSent(self, client: AmiClient, message: str):
        print("msg:" + message)

    def onConnect(self, client: AmiClient):
        print("Connected to server!")

    def onDisconnect(self, client: AmiClient):
        print("Disconnected from server!")

    def onLoggedIn(self, client: AmiClient):
        print("Logged in to AMI!")

    def onMessageReceived(self, client: AmiClient, now, seqnum, status, message: str):
        print(f"Message received from server '{message}' at {now} with sequence number {seqnum} and status {status}")

test = TestClient()