# 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](https://pypi.org/project/lightstreamer-client-lib/):
```
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](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.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:
```python
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](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.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](https://lightstreamer.com/docs/ls-server/latest/General%20Concepts.pdf)):
```python
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](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_api.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:
```python
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:
```python
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](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_api.LoggerProvider) and set it as the default provider of [LightstreamerClient](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.LightstreamerClient.setLoggerProvider).
```python
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
- [Live demos](https://demos.lightstreamer.com/?p=lightstreamer&t=client&lclient=python)
- [API Reference](https://lightstreamer.com/api/ls-python-client/2.2.0/index.html)
## Support
For questions and support please use the [Official Forum](https://forums.lightstreamer.com/). The issue list of this page is **exclusively** for bug reports and feature requests.
## License
[Apache 2.0](https://opensource.org/licenses/Apache-2.0)
Raw data
{
"_id": null,
"home_page": null,
"name": "lightstreamer-client-lib",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "lightstreamer, push, realtime, real-time",
"author": null,
"author_email": "Lightstreamer Srl <support@lightstreamer.com>",
"download_url": "https://files.pythonhosted.org/packages/f1/49/437077b8fdff13a78383ee13549380d7002164bac33efdef5e182c716660/lightstreamer_client_lib-2.2.0.tar.gz",
"platform": null,
"description": "# Lightstreamer Python Client SDK\n\nLightstreamer 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.\n\nThe 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.\n\n## Installation\n\nYou can install the Lightstreamer Client SDK from [PyPI](https://pypi.org/project/lightstreamer-client-lib/):\n\n```\npython -m pip install lightstreamer-client-lib\n```\n\nThe sdk is supported on Python 3.7 and above.\n\n## Quickstart\n\nTo connect to a Lightstreamer Server, a [LightstreamerClient](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.LightstreamerClient) object has to be created, configured, and instructed to connect to the Lightstreamer Server. \nA minimal version of the code that creates a LightstreamerClient and connects to the Lightstreamer Server on *https://push.lightstreamer.com* will look like this:\n\n```python\nfrom lightstreamer.client import *\n\nclient = LightstreamerClient(\"http://push.lightstreamer.com/\",\"DEMO\")\nclient.connect()\n```\n\nFor each subscription to be subscribed to a Lightstreamer Server a [Subscription](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.Subscription) instance is needed.\nA simple Subscription containing three items and two fields to be subscribed in *MERGE* mode is easily created (see [Lightstreamer General Concepts](https://lightstreamer.com/docs/ls-server/latest/General%20Concepts.pdf)):\n\n```python\nsub = Subscription(\"MERGE\",[\"item1\",\"item2\",\"item3\"],[\"stock_name\",\"last_price\"])\nsub.setDataAdapter(\"QUOTE_ADAPTER\")\nsub.setRequestedSnapshot(\"yes\")\nclient.subscribe(sub)\n```\n\nBefore sending the subscription to the server, usually at least one [SubscriptionListener](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_api.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:\n\n```python\nclass SubListener(SubscriptionListener):\n def onItemUpdate(self, update):\n print(\"UPDATE \" + update.getValue(\"stock_name\") + \" \" + update.getValue(\"last_price\"))\n\n # other methods...\n\nsub.addListener(SubListener())\n```\n\nBelow is the complete Python code:\n\n```python\nfrom lightstreamer.client import *\n\nsub = Subscription(\"MERGE\",[\"item1\",\"item2\",\"item3\"],[\"stock_name\",\"last_price\"])\nsub.setDataAdapter(\"QUOTE_ADAPTER\")\nsub.setRequestedSnapshot(\"yes\")\n\nclass SubListener(SubscriptionListener):\n def onItemUpdate(self, update):\n print(\"UPDATE \" + update.getValue(\"stock_name\") + \" \" + update.getValue(\"last_price\"))\n\nsub.addListener(SubListener())\n\nclient = LightstreamerClient(\"http://push.lightstreamer.com\",\"DEMO\")\nclient.subscribe(sub)\nclient.connect()\n```\n\n## Logging\n\nTo enable the internal client logger, create a [LoggerProvider](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_api.LoggerProvider) and set it as the default provider of [LightstreamerClient](https://lightstreamer.com/api/ls-python-client/2.2.0/lightstreamer.html#lightstreamer.client.ls_python_client_wrapper.LightstreamerClient.setLoggerProvider).\n\n```python\nimport sys, logging\n\nlogging.basicConfig(level=logging.DEBUG, format=\"%(message)s\", stream=sys.stdout)\n\nloggerProvider = ConsoleLoggerProvider(ConsoleLogLevel.DEBUG)\nLightstreamerClient.setLoggerProvider(loggerProvider)\n```\n\n## Compatibility ##\n\nCompatible with Lightstreamer Server since version 7.4.0.\n\n## Documentation\n\n- [Live demos](https://demos.lightstreamer.com/?p=lightstreamer&t=client&lclient=python)\n\n- [API Reference](https://lightstreamer.com/api/ls-python-client/2.2.0/index.html)\n\n## Support\n\nFor questions and support please use the [Official Forum](https://forums.lightstreamer.com/). The issue list of this page is **exclusively** for bug reports and feature requests.\n\n## License\n\n[Apache 2.0](https://opensource.org/licenses/Apache-2.0)\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Lightstreamer Client SDK",
"version": "2.2.0",
"project_urls": {
"Homepage": "https://github.com/Lightstreamer/Lightstreamer-lib-client-haxe"
},
"split_keywords": [
"lightstreamer",
" push",
" realtime",
" real-time"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0d2279641ec14bac56b0d7078a60dd2adc7259192c5a72b5c2fbd93e8da501f7",
"md5": "2b1178eebfa9fa2f577ec4cd9c856a79",
"sha256": "ade4436f60692bf171dc4782bdca7cc73d84966e8b0280908c8ddd5061e91c26"
},
"downloads": -1,
"filename": "lightstreamer_client_lib-2.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b1178eebfa9fa2f577ec4cd9c856a79",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 118760,
"upload_time": "2024-10-29T14:00:23",
"upload_time_iso_8601": "2024-10-29T14:00:23.104032Z",
"url": "https://files.pythonhosted.org/packages/0d/22/79641ec14bac56b0d7078a60dd2adc7259192c5a72b5c2fbd93e8da501f7/lightstreamer_client_lib-2.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f149437077b8fdff13a78383ee13549380d7002164bac33efdef5e182c716660",
"md5": "17b72b5cb7063f4eb21f448ab6b7c8c2",
"sha256": "7306e42707ebc40144879854e0aa568383f37e1e006e5430f96455867761a73c"
},
"downloads": -1,
"filename": "lightstreamer_client_lib-2.2.0.tar.gz",
"has_sig": false,
"md5_digest": "17b72b5cb7063f4eb21f448ab6b7c8c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 117096,
"upload_time": "2024-10-29T14:00:25",
"upload_time_iso_8601": "2024-10-29T14:00:25.005230Z",
"url": "https://files.pythonhosted.org/packages/f1/49/437077b8fdff13a78383ee13549380d7002164bac33efdef5e182c716660/lightstreamer_client_lib-2.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-29 14:00:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Lightstreamer",
"github_project": "Lightstreamer-lib-client-haxe",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "lightstreamer-client-lib"
}