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

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.1.tar.gz (117.0 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-2.2.1-py3-none-any.whl (118.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lightstreamer_client_lib-2.2.1.tar.gz
  • Upload date:
  • Size: 117.0 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.1.tar.gz
Algorithm Hash digest
SHA256 ca917c6e0c10572259e17ddcb7c288060841b958bb758854f797f60f754c9929
MD5 00a7715707dcba6bac25df71bd69d3b0
BLAKE2b-256 fd86b5fa3b0f014fcdf8b696b10adab5194cd0c7c2d03c570beeeccaac181cc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lightstreamer_client_lib-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58209b4d9b3c8dc47bedb44b54d5abb53ac81ad1b9b485deedcbb5bb6dede196
MD5 9215fa3570c804a83ceb6711dd36de8a
BLAKE2b-256 e3c55d19b5d93dd04b23ed7cb12301bf106e7e5a50279f19b9277f588cf37ccf

See more details on using hashes here.

Release history Release notifications | RSS feed

2.2.3

2 files

2.2.2

2 files

This release

2.2.1 This release

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 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