Skip to main content

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

Release files for lightstreamer-client-lib 2.2.3

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 2.2.3
File Size Uploaded
lightstreamer_client_lib-2.2.3.tar.gz 119.4 kB Details

Built distribution (wheel)

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

Total release size: 240.6 kB

Release files / lightstreamer_client_lib-2.2.3.tar.gz

Download URL lightstreamer_client_lib-2.2.3.tar.gz
Size 119.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2c0cf48d79457aa133b0c35b02589ba260efa835b46c06bb20afcee0f4a05fb8
BLAKE2b-256 checksum
How to use checksums
cd6c4f439d60b894ef17ad8c7608408609c0ff1fa6fe83a00835c12e23845ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / lightstreamer_client_lib-2.2.3-py3-none-any.whl

Download URL lightstreamer_client_lib-2.2.3-py3-none-any.whl
Size 121.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdf8e36838f650796fd47427193c9b8dc19f91a005947d70d8978cfc19ca4726
BLAKE2b-256 checksum
How to use checksums
e26e5ddc3b66a3fb8437c1a7a2b09a0b8b8eb6ab81ba04f7fa918784a78e715e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

2.2.3 This release

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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