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.9 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:
  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:
  def onItemUpdate(self, update):
    print("UPDATE " + update.getValue("stock_name") + " " + update.getValue("last_price"))
  def onListenStart(self, aSub):
    pass
  def onClearSnapshot(self, itemName, itemPos):
    pass
  def onCommandSecondLevelItemLostUpdates(self, lostUpdates, key):
    pass
  def onCommandSecondLevelSubscriptionError(self, code, message, key):
    pass
  def onEndOfSnapshot(self, itemName, itemPos):
    pass
  def onItemLostUpdates(self, itemName, itemPos, lostUpdates):
    pass
  def onListenEnd(self, subscription):
    pass
  def onListenStart(self, subscription):
    pass
  def onSubscription(self):
    pass
  def onSubscriptionError(self, code, message):
    pass
  def onUnsubscription(self):
    pass
  def onRealMaxFrequency(self, frequency):
    pass

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.

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

Compatibility

Compatible with Lightstreamer Server since version 7.2.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-1.0.0b2.tar.gz (88.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightstreamer_client_lib-1.0.0b2-py3-none-any.whl (89.2 kB view details)

Uploaded Python 3

File details

Details for the file lightstreamer-client-lib-1.0.0b2.tar.gz.

File metadata

File hashes

Hashes for lightstreamer-client-lib-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 5feba7c237843d4a4aa61998d6e43e551a116660efa1acec7a1045cbaf5145f7
MD5 765d6e1ccadf8556a2e30298096df087
BLAKE2b-256 c54b09c12ab7990196aa6d62eaa87a38f6b3c27308b8ca1df86aa0eeabb11696

See more details on using hashes here.

File details

Details for the file lightstreamer_client_lib-1.0.0b2-py3-none-any.whl.

File metadata

File hashes

Hashes for lightstreamer_client_lib-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4bbdc358ec8857d89ca35acf40b83a97126ea250041b1265d15c4bd2eb48f9
MD5 0c03644e2b5d964b9ef3f3de61875ec0
BLAKE2b-256 d79db56c1ff74fd9acba3bc51088496d889ee8008d2d3a88ebd1c0bc09b0f916

See more details on using hashes here.

Supported by

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