Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

Metadata

Release files for lightstreamer-client-lib 1.0.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lightstreamer-client-lib 1.0.0b1
File Size Uploaded Provenance Actions
lightstreamer-client-lib-1.0.0b1.tar.gz 88.2 kB Without provenance Details for lightstreamer-client-lib-1.0.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lightstreamer-client-lib 1.0.0b1
File Interpreter ABI Platform Actions
lightstreamer_client_lib-1.0.0b1-py3-none-any.whl Python 3 none any Details for lightstreamer_client_lib-1.0.0b1-py3-none-any.whl

Total release size: 177.4 kB

Release files / lightstreamer-client-lib-1.0.0b1.tar.gz

Download URL lightstreamer-client-lib-1.0.0b1.tar.gz
Size 88.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d4e641a31bf61dd1916be531baa5e99b266d88d8fa8256acafad831adc15537d
BLAKE2b-256 checksum
How to use checksums
164279eb7b2340bdf0f4dafbd7a963bd3675a62bfeffa3a05a98657119f403d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / lightstreamer_client_lib-1.0.0b1-py3-none-any.whl

Download URL lightstreamer_client_lib-1.0.0b1-py3-none-any.whl
Size 89.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c9d520cd467c879c329ed4bb54030fd7b76f5005a56216c59cccbc6534149d0
BLAKE2b-256 checksum
How to use checksums
8372e8e332cbaaae75f5ce94a9bfdc0f93ae51728285cda30c85dba5eaa99af0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for lightstreamer-client-lib 1.0.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page