Package: lightstreamer-adapter
A Python library to  write Data Adapters and Metadata Adapters forLightstreamer Server.
The adapters will run in a separate process, communicating with the Server through the Adapter Remoting Infrastructure.UseInstall the package:$pipinstalllightstreamer-adapterConfigure LightstreamerDownload and install LightstreamerGo to theadaptersfolder of your Lightstreamer Server installation. Create a new folder to deploy the remote adapters in, let’s call itPythonAdapterCreate anadapters.xmlfile inside thePythonAdapterfolder and use the following contents (this is an example configuration, you can modify it to your liking by using the generic template,https://lightstreamer.com/docs/ls-server/latest/remote_adapter_conf_template/adapters.xmlorhttps://lightstreamer.com/docs/ls-server/latest/remote_adapter_robust_conf_template/adapters.xml, as a reference):<?xml version="1.0"?><adapters_confid="PROXY_PYTHON"><metadata_provider><adapter_class>ROBUST_PROXY_FOR_REMOTE_ADAPTER</adapter_class><classloader>log-enabled</classloader><paramname="request_reply_port">8003</param><paramname="timeout">36000000</param></metadata_provider><data_provider><adapter_class>ROBUST_PROXY_FOR_REMOTE_ADAPTER</adapter_class><classloader>log-enabled</classloader><paramname="request_reply_port">8001</param><paramname="timeout">36000000</param></data_provider></adapters_conf>Take note of the ports configured in the adapters.xml file as those are needed to write the remote part of the adapters.Write the AdaptersCreate a new python module, let’s call itadapters.py, where we will put  the minimal logic required to write a basic Adapter Set.Import the server classes needed to setup the connection to the Lightstreamer server, and the adapter classes to be extended to write your own Remote Adapters:fromlightstreamer_adapter.serverimport(DataProviderServer,MetadataProviderServer)fromlightstreamer_adapter.interfaces.dataimportDataProviderfromlightstreamer_adapter.interfaces.metadataimportMetadataProviderCreate a new Remote Data Adapter by subclassing the DataProvider abstract class:classMyDataAdapter(DataProvider):"""This Remote Data Adapter sample class shows a simple implementation of
    the DataProvider abstract class."""def__init__(self):# Reference to the provided ItemEventListener instanceself._listener=Nonedefissnapshot_available(self,item_name):"""Returns True if Snapshot information will be sent for the item_name
        item before the updates."""snapshot=False# May be based on the item_name itemreturnsnapshotdefset_listener(self,event_listener):"""Caches the reference to the provided ItemEventListener instance."""self._listener=event_listenerdefsubscribe(self,item_name):"""Invoked to request data for an item. From now on you can start
        sending real time updates for item_name item, through invocations like
        the following:

        self._listener.update(item_name, {'field1': valField1,
                                          'field2': valField2}, False)
        """defunsubscribe(self,item_name):"""Invoked to end a previous request of data for an item. From now on,
        you should stop sending updates for item_name item."""Create a new Remote Metadata Adapter by subclassing the MetadataProvider class, if the latter’s default behaviour does not meet your requirements, and override the methods for which you want to supply a custom implementation:classMyMetadataAdapter(MetadataProvider):"""This Remote Metadata Adapter sample class shows a minimal custom
    implementation of the notify_user_message method.
    """defnotify_user_message(self,user,session_id,message):"""Invoked to forward a message received by a User"""print("Message{}arrived for user{}in the session{}".format(user,session_id,message))Run the adapters, by creating, configuring and starting the server class instances:if__name__=="__main__":# The host of the Lightstreamer server, to be changed as required.LS_SERVER_HOST='localhost'# Creates a new MetadataProviderServer instance, passing a new# MyMetadataAdpater object and the remote address.metadata_provider_server=MetadataProviderServer(MyMetadataAdapter(),(LS_SERVER_HOST,8003))# Starts the server instance.metadata_provider_server.start()# Creates a new DataProviderServer instance, passing a new MyDataAdpater# object and the remote addressdata_provider_sever=DataProviderServer(MyDataAdapter(),(LS_SERVER_HOST,8001))# Starts the server instance.data_provider_sever.start()Ensure that the main thread stays alive. This is needed, since Python 3.9, to allow the SDK library to take advantage of the system’s ThreadPoolExecutor class. Here we show a simple way to do so:fromthreadingimportEvent.....shutdown_event=Event()shutdown_event.wait()RunFrom the command line, execute:$pythonadapters.pyConnect a ClientvarlsClient=newLightstreamerClient(LS_SERVER_HOST,"PROXY_PYTHON");lsClient.connect();// To be completed with other client side activities, like registration of subscriptions and handling of// real time updates.// ...whereLS_SERVER_HOSTis the host of the Lightstreamer Server, and"PROXY_PYTHON"is the Adapter Set ID as specified in theadapters.xmlfile.API ReferenceAPI Reference is available athttps://lightstreamer.com/api/ls-python-adapter/1.3.1/.You can generate it by executing the following command from thedocfolder:$makehtmlThe generated documentation will be available under thedoc\_build\htmlfolder.See AlsoAdapter Remoting Infrastructure Network Protocol SpecificationLightstreamer Chat Demo adapter for PythonLightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.4.
- For a version of this library compatible with Adapter Remoting Infrastructure for Server version 7,3, please refer tothis tag.
- For a version of this library compatible with Adapter Remoting Infrastructure for Server version 6.0 (corresponding to Adapter Remoting Infrastructure 1.7), please refer tothis older tag.Release History1.3.1 (2023-12-11)ImprovementsStored the API docs on a different place.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.4.1.3.0 (2023-07-17)New FeaturesIntroduced the support for a single connection instead of two for the
communication of the Remote Data Adapters.
In fact, since Server version 7.4, the Proxy Data Adapter can (and should)
be configured to use a single connection for the communication.
Hence, the “address” argument of __init__ for the DataProviderServer class,
which is a tuple, can now have only 2 values (including one port); a tuple
with 3-values will now be refused.
As a consequence, if an existing Remote Server based on the previous
version of this SDK launches a Remote Data Adapter, it cannot be upgraded
to this new SDK version seamlessly.
The upgrade will require a change in the code to supply a single
port for the connection to the Proxy Data Adapter. This, in turn, will
require the configuration of a single port on the Proxy Data Adapter,
which is only possible with Lightstreamer Server 7.4 or later.
However, if a Remote Server only launches Remote Metadata Adapters,
the compatibility with Server version 7.3 is kept.Thoroughly modified the supplied unit tests to implement the single-connection
behavior and the new compatibility rules.ImprovementsRevised the supplied unit tests to clarifiy dequeueing from the sockets
and expected messages.Clarified the meaning of a None or missing value for a “userMsg” argument
supplied in a CreditsError: an empty string should be sent to the client.
Note that, previously, the Server used to send the “null” string as a
placeholder. Hence, Adapters relying on this behavior should now supply
“null” explicitly.*Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.4.1.2.3 (2023-03-21)ImprovementsAdded handling of runtime exceptions in the internal threads, by submitting
them to the exception handlers and extended the default handling of runtime
exceptions by always showing the stack trace.Added a unit test on keepalive packets for the notify connection.
Also improved unit tests log to better identify the current test.Added documentation notes regarding the compatibility with Python 3.9 and
later. See “start” in MetadataProviderServer and DataProviderServer.Bug FixesFixed a race condition which could have caused the RAC message to be sent
too late and break the protocol. However, this could only happen when the
Proxy Adapter had no credential check configured.Addressed possible race conditions in the unit tests.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.0.1.2.2 (2021-08-30)ImprovementsIntroduced full support for Server version 7.2. Now the library can log any
message sent by the Proxy Adapter when forcibly closing the connection.Modified the behavior when incomplete credentials are configured: now they
are sent to the Proxy Adapter, whereas previously they were not sent.
Note that, if the Proxy Adapter has credentials configured, they cannot be
incomplete; hence the Proxy Adapter is expected to refuse the connection in
all cases.Bug FixesFixed a bug on the handling of keepalives on the notification channel of the
Data Adapter, which may have caused the Proxy Adapter to close the connection
due to a keepalive timeout, if configured. This had the highest probability
to happen in case of a reduced overall data flow, or during the startup phase.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.0.1.2.1 (2021-05-25)ImprovementsReformulated the compatibility constraint with respect to the Server version,
instead of the Adapter Remoting Infrastructure version.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since Server version 7.0.1.2.0 (2020-01-24)ImprovementsExtended DataProviderServer and MetadataProviderServer (through the Server
superclass) with settings of credentials, to be sent to the Proxy Adapter
upon each connection. Credential check is an optional configuration of the
Proxy Adapter; if not leveraged, the credentials will be ignored.Modified the handling of the keepalives when connected to a Proxy Adapter
(i.e. Adapter Remoting Infrastructure) version 1.9
(corresponding to Server 7.1) or higher: the preferred
keepalive interval requested by the Proxy Adapter, when stricter than the
configured one, is now obeyed (with a safety minimun of 1 second). Moreover,
in that case, the default interval configuration is now 10 seconds instead of
1. If an existing installation relies on a very short keepalive interval to
keep the connection alive due to intermediate nodes, the time should now be
explicitly configured.Added full support for ARI Protocol extensions introduced in Adapter Remoting
Infrastructure version 1.9 (corresponding to Server 7.1).Added full support for TLS/SSL encrypted connections the Proxy Adapters.Added clarifications in the documentation of the exception handlers and fix
a few obsolete notes.Added clarifications in the documentation of MetadataProviderServer and
DataProviderServer classes.Improved code layout as per pylint/pycodestyle outputs.Remove useless “pass” statement from classes of the interfaces package.Updated unit tests according to new featuresBug FixesRemoved useless optional client_principal parameter from the
MetadataProvider.notify_user method.Fixed documentation of the DataProvider class, where “Lightstreamer Kernel”
was erroneously referred as “Lightstreamer1”.Fixed broken links in the documentation of the DataProviderServer class.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.1.4 (2019-03-29)Bug FixesFixed a bug that caused requests sent from Lightstreamer instances running on
non-Windows platform not to be parsed correctly (see #2).Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.1.3 (2019-03-28)Bug FixesFixed parsing issue when subscribing to more than two items.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.1.2 (2018-02-22)ImprovementsAdded clarifications on licensing matters in the docs.Bug FixesFixed edition note in the documentation of notify_user_with_principal.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.1.1 (2017-12-22)ImprovementsMoved API documentation tohttp://lightstreamer-lib-python-adapter.readthedocs.io/en/latest/.Fixed few source code fragments to make them PEP 8 compliant.Bug FixesFixed Lightstreamer Compatibility Notes in the README file.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.1.0 (2017-12-19)ImprovementsModified the signature of the notify_mpn_device_access and
notify_mpn_device_token_change methods of the MetadataProvider class,
to add a session ID argument.
Existing Remote Metadata Adapters leveraging notify_mpn_device_access
and/or notify_mpn_device_token_change have to be ported to the new signature.Revised the public constants defined in the MpnPlatformType class.
The constants referring to the supported platforms have got new names,
whereas the constants for platforms not yet supported have been removed.
Existing Remote Metadata Adapters explicitly referring to the constants
have to be aligned.Removed the subclasses of MpnSubscriptionInfo (namely
MpnApnsSubscriptionInfo and MpnGcmSubscriptionInfo) that were used
by the SDK library to supply the attributes of the MPN subscriptions
in notify_mpn_subscription_activation. Now, simple instances of
MpnSubscriptionInfo will be supplied and attribute information can be
obtained through the new “notification_format” property.
See the MPN chapter on the General Concepts document for details on the
characteristics of the Notification Format.
Existing Remote Metadata Adapters
leveraging notify_mpn_subscription_activation and inspecting the supplied
MpnSubscriptionInfo have to be ported to the new class contract.Improved the interface documentation of MPN-related methods.Clarified in the docs for notifySessionClose which race conditions with other
methods can be expected.Aligned the documentation to comply with current licensing policies.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.8
(corresponding to Server 7.0).1.0.0.post1 (2016-11-22)Finishing touches on the package documentation visible from the PyPi repository1.0.0 (2016-11-22)ImprovementsUpdated logging messages.Bug FixesFixed notification of End Of Snaphsot in case of not availability of the snapshot.Fixed docstrings in moduleslightstreamer_adapter/server.pyandlightstreamer_adapter/subscription.py.Fixed unit tests.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.7
(corresponding to Server 6.0).1.0.0b1 (2016-04-15)Bug FixesFixed docstrings.Fixed typo in some Exceptions’ message.Fixed unit tests.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.7
(corresponding to Server 6.0).1.0.0a2 (2016-04-08)Bug FixesFixed return values inlightstreamer_adapter.interfaces.metadata.MetadataProviderclass.Fixed default handling of I/O related errors.Fixed docstrings in moduleslightstreamer_adapter/data_protocol.pyandlightstreamer_adapter/metadata_protocol.py.Lightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.7
(corresponding to Server 6.0).1.0.0a1 (2016-04-08)Initial releaseLightstreamer Compatibility NotesCompatible with Adapter Remoting Infrastructure since 1.7
(corresponding to Server 6.0).