Skip to main content

Lightstreamer Client SDK

Project description

Lightstreamer Python Client SDK

Lightstreamer Python Client SDK enables any Python application to communicate bidirectionally with a Lightstreamer Server. The API allows to subscribe to real-time data pushed by the server and to send any message to the server.

The library offers automatic recovery from connection failures, automatic selection of the best available transport, and full decoupling of subscription and connection operations. It is responsible of forwarding the subscriptions to the Server and re-forwarding all the subscriptions whenever the connection is broken and then reopened.

Installation

You can install the Lightstreamer Client SDK from PyPI:

python -m pip install lightstreamer-client-lib

The sdk is supported on Python 3.7 and above.

Quickstart

To connect to a Lightstreamer Server, a LightstreamerClient object has to be created, configured, and instructed to connect to the Lightstreamer Server. A minimal version of the code that creates a LightstreamerClient and connects to the Lightstreamer Server on https://push.lightstreamer.com will look like this:

from lightstreamer.client import *

client = LightstreamerClient("http://push.lightstreamer.com/","DEMO")
client.connect()

For each subscription to be subscribed to a Lightstreamer Server a Subscription instance is needed. A simple Subscription containing three items and two fields to be subscribed in MERGE mode is easily created (see Lightstreamer General Concepts):

sub = Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"])
sub.setDataAdapter("QUOTE_ADAPTER")
sub.setRequestedSnapshot("yes")
client.subscribe(sub)

Before sending the subscription to the server, usually at least one SubscriptionListener is attached to the Subscription instance in order to consume the real-time updates. The following code shows the values of the fields stock_name and last_price each time a new update is received for the subscription:

class SubListener(SubscriptionListener):
  def onItemUpdate(self, update):
    print("UPDATE " + update.getValue("stock_name") + " " + update.getValue("last_price"))

  # other methods...

sub.addListener(SubListener())

Below is the complete Python code:

from lightstreamer.client import *

sub = Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"])
sub.setDataAdapter("QUOTE_ADAPTER")
sub.setRequestedSnapshot("yes")

class SubListener(SubscriptionListener):
  def onItemUpdate(self, update):
    print("UPDATE " + update.getValue("stock_name") + " " + update.getValue("last_price"))

sub.addListener(SubListener())

client = LightstreamerClient("http://push.lightstreamer.com","DEMO")
client.subscribe(sub)
client.connect()

Logging

To enable the internal client logger, create a LoggerProvider and set it as the default provider of LightstreamerClient.

import sys, logging

logging.basicConfig(level=logging.DEBUG, format="%(message)s", stream=sys.stdout)

loggerProvider = ConsoleLoggerProvider(ConsoleLogLevel.DEBUG)
LightstreamerClient.setLoggerProvider(loggerProvider)

Compatibility

Compatible with Lightstreamer Server since version 7.4.0.

Documentation

Support

For questions and support please use the Official Forum. The issue list of this page is exclusively for bug reports and feature requests.

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lightstreamer_client_lib-2.2.2.tar.gz (117.6 kB view details)

Uploaded Source

Built Distribution

lightstreamer_client_lib-2.2.2-py3-none-any.whl (119.4 kB view details)

Uploaded Python 3

File details

Details for the file lightstreamer_client_lib-2.2.2.tar.gz.

File metadata

  • Download URL: lightstreamer_client_lib-2.2.2.tar.gz
  • Upload date:
  • Size: 117.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for lightstreamer_client_lib-2.2.2.tar.gz
Algorithm Hash digest
SHA256 1b967093217d49cb3e19930db4405139d2aa2345b1d868de470ec1d1eee8cc1b
MD5 c44f99e40c051759d3c9323d12d6593f
BLAKE2b-256 abc255cd668d47a25c600de1bb1c2841c57f4b460901795367b0de6c4f628cbf

See more details on using hashes here.

File details

Details for the file lightstreamer_client_lib-2.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lightstreamer_client_lib-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0c41da1b138a8c3dc0f714e4fa532174b5c335dedc74e789bce8dd5f7a34788
MD5 e0e9711a7db5ef5cb5194df8ee35fd66
BLAKE2b-256 b148f5c58bd9407dee034a8580ff8e24bee203b6887a44e05e72edee2d5631ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page