Python Client Setup

This page provides instructions for setting up the Python client, including installation and configuration steps to enable communication with the XTABLES server.

XTablesClient Python Package

Installation

To install the XTablesClient Python package, use the following pip command:

pip install XTablesClient

Importing

After installation, you can import the XTablesClient as follows:

from JXTABLES import XTablesClient

XTablesClient Class

The XTablesClient class allows you to communicate with the XTABLES server using ZeroMQ (ZMQ). Below are the details of the methods and usage.

Constructor

def __init__(self, ip=None, push_port=1735, req_port=1736, sub_port=1737, buffer_size=500):
  • ip: The IP address of the XTABLES server. When None, it will resolve the host automatically.

  • push_port: The port for the PUSH socket.

  • req_port: The port for the REQ socket.

  • sub_port: The port for the SUB socket.

  • buffer_size: The buffer size for the subscribe circular buffer.

The constructor connects to the XTABLES server and initializes the sockets. If no IP address is provided, the client will attempt to resolve the XTABLES hostname.


Method: shutdown()

Closes all sockets and stops the subscribe handler.


Method: connect()

Attempts to reconnect the sockets to the server and re-initialize subscriptions.


Method: send_push_message()

Sends a push message to the server.

  • command: The command to execute (e.g., PUT, PUBLISH).

  • key: The key associated with the message.

  • value: The value associated with the key.

  • msg_type: The message type (e.g., BYTES, STRING, INT64).


Method: publish()

Publish a message to the server with the given key and value.


Method: subscribe()

Subscribes to a specific key and associates a consumer function to process updates.

  • key: The key to subscribe to.

  • consumer: The consumer function to process updates.


Method: subscribe_all()

Subscribes to updates for all keys and associates a consumer function to process updates.


Method: unsubscribe()

Unsubscribes a specific consumer from a given key. If no consumers remain, the key is unsubscribed.

  • key: The key to unsubscribe from.

  • consumer: The consumer function to remove.


Method: unsubscribe_all()

Unsubscribes a specific consumer from all keys.


PUT Methods

These methods allow you to send data to the server with different types.

  • putBytes: Sends a byte array.

  • putUnknownBytes: Sends unknown bytes.

  • putString: Sends a string.

  • putInteger: Sends an integer.

  • putLong: Sends a long integer.

  • putDouble: Sends a double.

  • putBoolean: Sends a boolean value.

  • putArray: Sends an array of values.


GET Methods

These methods retrieve data from the server. They return None if no data is available.

  • getString: Retrieves a string value.

  • getInteger: Retrieves an integer value.

  • getBoolean: Retrieves a boolean value.

  • getLong: Retrieves a long integer value.

  • getDouble: Retrieves a double value.

  • getArray: Retrieves an array of values.

  • getBytes: Retrieves a byte array.

  • getUnknownBytes: Retrieves unknown bytes.


Method: ping()

Sends a ping to the server and measures the round-trip time. Returns a PingResponse object with the result.


Version and Properties Methods

  • get_version: Retrieves the client version.

  • add_client_version_property: Adds a custom property to the client version.


Example Usage


Conclusion

This documentation covers the basic usage and setup of the XTablesClient Python package. For advanced use cases, you can leverage the methods to manage data communication with the XTABLES server.

Last updated