Skip to content

Commit 9b08773

Browse files
committed
Refactor code structure for improved readability and maintainability, update LD Lib version
1 parent a21f191 commit 9b08773

6 files changed

Lines changed: 201 additions & 175 deletions

File tree

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Machine Readable News Example with LSEG Data Library for Python
22

3-
- Last update: January 2025
3+
- Last update: April 2025
44
- Compiler: Python
55
- Prerequisite: The Real-Time Distribution System or The Real-Time -- Optimized credentials (V1) with MRN service
66

@@ -19,6 +19,29 @@ This example requires the following dependencies.
1919

2020
Please contact your LSEG representative to help you to access the RTO account and services.
2121

22+
## <a id="rdp_lib"></a>Introduction to the Data Library for Python
23+
24+
The [Data Library for Python](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python) provides a set of ease-of-use interfaces offering coders uniform access to the breadth and depth of financial data and services available on the Workspace, RDP, and Real-Time Platforms. The API is designed to provide consistent access through multiple access channels and target both Professional Developers and Financial Coders. Developers can choose to access content from the desktop, through their deployed streaming services, or directly to the cloud. With the Data Library, the same Python code can be used to retrieve data regardless of which access point you choose to connect to the platform.
25+
26+
![Figure-1](images/datalib_image.png "Data Library Diagram")
27+
28+
The Data Library are available in the following programming languages:
29+
30+
- [Python](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python)
31+
- [.NET](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-net)
32+
- [TypeScript](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-library-for-typescript)
33+
34+
For more deep detail regarding the Data Library for Python, please refer to the following articles and tutorials:
35+
36+
- [Quickstart](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python/quick-start).
37+
- [Documentation](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python/documentation).
38+
- [Tutorials](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python/tutorials).
39+
- [GitHub](https://github.com/LSEG-API-Samples/Example.DataLibrary.Python).
40+
41+
### Disclaimer
42+
43+
This project is based on Data Library Python versions **2.1.1**.
44+
2245
## <a id="news_mrn_overview"></a>Machine Readable News Overview
2346

2447
Machine Readable News (MRN) is an advanced service for automating the consumption and systematic analysis of news. It delivers deep historical news archives, ultra-low latency structured news and news analytics directly to your applications. This enables algorithms to exploit the power of news to seize opportunities, capitalize on market inefficiencies, and manage event risk.

images/datalib_image.png

47.2 KB
Loading

requirements-notebook.txt

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,102 @@
1-
anyio==4.8.0
1+
anyio==4.9.0
22
appdirs==1.4.4
33
argon2-cffi==23.1.0
44
argon2-cffi-bindings==21.2.0
55
arrow==1.3.0
66
asttokens==3.0.0
7-
async-lru==2.0.4
8-
attrs==24.3.0
9-
babel==2.16.0
10-
beautifulsoup4==4.12.3
7+
async-lru==2.0.5
8+
attrs==25.3.0
9+
babel==2.17.0
10+
beautifulsoup4==4.13.4
1111
bleach==6.2.0
12-
certifi==2024.12.14
12+
certifi==2025.1.31
1313
cffi==1.17.1
1414
charset-normalizer==3.4.1
1515
colorama==0.4.6
1616
comm==0.2.2
17-
debugpy==1.8.11
18-
decorator==5.1.1
17+
debugpy==1.8.14
18+
decorator==5.2.1
1919
defusedxml==0.7.1
20-
exceptiongroup==1.2.2
21-
executing==2.1.0
20+
executing==2.2.0
2221
fastjsonschema==2.21.1
2322
fqdn==1.5.1
2423
h11==0.14.0
25-
httpcore==1.0.7
26-
httpx==0.26.0
24+
httpcore==1.0.8
25+
httpx==0.27.2
2726
idna==3.10
2827
ipykernel==6.29.5
29-
ipython==8.31.0
28+
ipython==9.1.0
29+
ipython_pygments_lexers==1.1.1
3030
isoduration==20.11.0
3131
jedi==0.19.2
32-
Jinja2==3.1.5
33-
json5==0.10.0
32+
Jinja2==3.1.6
33+
json5==0.12.0
3434
jsonpointer==3.0.0
3535
jsonschema==4.23.0
3636
jsonschema-specifications==2024.10.1
37-
jupyter-events==0.11.0
37+
jupyter-events==0.12.0
3838
jupyter-lsp==2.2.5
3939
jupyter_client==8.6.3
4040
jupyter_core==5.7.2
4141
jupyter_server==2.15.0
4242
jupyter_server_terminals==0.5.3
43-
jupyterlab==4.3.4
43+
jupyterlab==4.4.0
4444
jupyterlab_pygments==0.3.0
4545
jupyterlab_server==2.27.3
46-
lseg-data==2.0.1
46+
lseg-data==2.1.1
4747
MarkupSafe==3.0.2
4848
matplotlib-inline==0.1.7
49-
mistune==3.1.0
49+
mistune==3.1.3
5050
nbclient==0.10.2
51-
nbconvert==7.16.5
51+
nbconvert==7.16.6
5252
nbformat==5.10.4
5353
nest-asyncio==1.6.0
5454
notebook_shim==0.2.4
55-
numpy==1.26.4
55+
numpy==2.2.4
5656
overrides==7.7.0
5757
packaging==24.2
5858
pandas==2.2.3
5959
pandocfilters==1.5.1
6060
parso==0.8.4
61-
platformdirs==4.3.6
61+
platformdirs==4.3.7
6262
prometheus_client==0.21.1
63-
prompt_toolkit==3.0.48
64-
psutil==6.1.1
63+
prompt_toolkit==3.0.51
64+
psutil==7.0.0
6565
pure_eval==0.2.3
6666
pycparser==2.22
67-
pyee==11.1.0
67+
pyee==12.0.0
6868
Pygments==2.19.1
6969
pyhumps==3.8.0
7070
python-dateutil==2.9.0.post0
71-
python-json-logger==3.2.1
72-
pytz==2024.2
73-
pywin32==308; platform_system == "Windows"
74-
pywinpty==2.0.14; platform_system == "Windows"
71+
python-json-logger==3.3.0
72+
pytz==2025.2
73+
pywin32==310
74+
pywinpty==2.0.15
7575
PyYAML==6.0.2
76-
pyzmq==26.2.0
77-
referencing==0.35.1
76+
pyzmq==26.4.0
77+
referencing==0.36.2
7878
requests==2.32.3
7979
rfc3339-validator==0.1.4
8080
rfc3986-validator==0.1.1
81-
rpds-py==0.22.3
82-
scipy==1.12.0
81+
rpds-py==0.24.0
82+
scipy==1.15.2
8383
Send2Trash==1.8.3
84-
simplejson==3.19.3
84+
simplejson==3.20.1
8585
six==1.17.0
8686
sniffio==1.3.1
8787
soupsieve==2.6
8888
stack-data==0.6.3
89-
tenacity==8.5.0
89+
tenacity==9.1.2
9090
terminado==0.18.1
9191
tinycss2==1.4.0
92-
tomli==2.2.1
9392
tornado==6.4.2
9493
traitlets==5.14.3
9594
types-python-dateutil==2.9.0.20241206
96-
typing_extensions==4.12.2
97-
tzdata==2024.2
95+
typing_extensions==4.13.2
96+
tzdata==2025.2
9897
uri-template==1.3.0
99-
urllib3==2.3.0
100-
watchdog==2.3.1
98+
urllib3==2.4.0
99+
watchdog==6.0.0
101100
wcwidth==0.2.13
102101
webcolors==24.11.1
103102
webencodings==0.5.1

requirements.txt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
anyio==4.8.0
1+
anyio==4.9.0
22
appdirs==1.4.4
3-
certifi==2024.12.14
3+
certifi==2025.1.31
44
charset-normalizer==3.4.1
5-
exceptiongroup==1.2.2
65
h11==0.14.0
7-
httpcore==1.0.7
8-
httpx==0.26.0
6+
httpcore==1.0.8
7+
httpx==0.27.2
98
idna==3.10
10-
Jinja2==3.1.5
11-
lseg-data==2.0.1
9+
Jinja2==3.1.6
10+
lseg-data==2.1.1
1211
MarkupSafe==3.0.2
13-
numpy==1.26.4
12+
numpy==2.2.4
1413
pandas==2.2.3
15-
pyee==11.1.0
14+
pyee==12.0.0
1615
pyhumps==3.8.0
1716
python-dateutil==2.9.0.post0
18-
pytz==2024.2
17+
pytz==2025.2
1918
requests==2.32.3
20-
scipy==1.12.0
21-
simplejson==3.19.3
19+
scipy==1.15.2
20+
simplejson==3.20.1
2221
six==1.17.0
2322
sniffio==1.3.1
24-
tenacity==8.5.0
25-
typing_extensions==4.12.2
26-
tzdata==2024.2
27-
urllib3==2.3.0
28-
watchdog==2.3.1
23+
tenacity==9.1.2
24+
typing_extensions==4.13.2
25+
tzdata==2025.2
26+
urllib3==2.4.0
27+
watchdog==6.0.0
2928
websocket-client==1.8.0

src/OMMStream-MRN-LD.ipynb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Machine Readable News Example with LSEG Data Library for Python\n",
88
"\n",
9-
"- Last update: January 2025\n",
9+
"- Last update: April 2025\n",
1010
"\n",
1111
"This example shows how developers may use the [LSEG Data Library for Python](https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python) Delivery layer feature to subscribe to the Machine Readable News (MRN) from LSEG Real-Time Distribution System (RTDS) and LSEG Real-Time Optimized (RTO). The example just connects to LSEG Real-Time platform via a WebSocket connection, then subscribes and displays MRN News data in a console. "
1212
]
@@ -56,14 +56,14 @@
5656
"# Import all required library\n",
5757
"\n",
5858
"import sys\n",
59-
"import lseg.data as ld\n",
60-
"from lseg.data.delivery import omm_stream\n",
6159
"import datetime\n",
6260
"import time\n",
6361
"import json\n",
6462
"import base64\n",
6563
"import zlib\n",
66-
"import binascii"
64+
"import binascii\n",
65+
"import lseg.data as ld\n",
66+
"from lseg.data.delivery import omm_stream"
6767
]
6868
},
6969
{
@@ -76,7 +76,7 @@
7676
"_news_envelopes = []\n",
7777
"RIC_CODE = 'MRN_STORY'\n",
7878
"DOMAIN = 'NewsTextAnalytics'\n",
79-
"SERVICE = 'ELEKTRON_DD'\n"
79+
"SERVICE = 'ELEKTRON_DD'"
8080
]
8181
},
8282
{
@@ -88,16 +88,15 @@
8888
},
8989
{
9090
"cell_type": "code",
91-
"execution_count": 9,
91+
"execution_count": null,
9292
"metadata": {},
9393
"outputs": [],
9494
"source": [
95-
"# Retrieve data\n",
96-
"# Callback function to display data or status events\n",
9795
"def display_event(eventType, event):\n",
98-
" currentTime = datetime.datetime.now().time()\n",
99-
" print(\"----------------------------------------------------------\")\n",
100-
" print(\">>> {} event received at {}\".format(eventType, currentTime))\n",
96+
" \"\"\"Retrieve data: Callback function to display data or status events. \"\"\"\n",
97+
" current_time = datetime.datetime.now().time()\n",
98+
" print('----------------------------------------------------------')\n",
99+
" print(f'>>> {eventType} event received at {current_time}')\n",
101100
" print(json.dumps(event, indent=2))\n",
102101
" return"
103102
]
@@ -111,13 +110,13 @@
111110
},
112111
{
113112
"cell_type": "code",
114-
"execution_count": 3,
113+
"execution_count": null,
115114
"metadata": {},
116115
"outputs": [],
117116
"source": [
118-
"def process_mrn_update(eventType, event): \n",
117+
"def process_mrn_update(event): \n",
118+
" \"\"\"Process MRN Update messages.\"\"\"\n",
119119
" message_json = event\n",
120-
" \"\"\"Function process Update Message for MRN domain data\"\"\"\n",
121120
" fields_data = message_json['Fields']\n",
122121
"\n",
123122
" # declare variables\n",
@@ -192,8 +191,8 @@
192191
" # Some console environments like Windows may encounter this unicode display as a limitation of OS\n",
193192
" except UnicodeEncodeError as encodeerror:\n",
194193
" print(f'UnicodeEncodeError exception. Cannot decode unicode character for {guid} in this environment: ', encodeerror)\n",
195-
" except Exception as e:\n",
196-
" print('exception: ', sys.exc_info()[0])"
194+
" except Exception as specific_error:\n",
195+
" print(f'exception: str{specific_error}', sys.exc_info()[0])"
197196
]
198197
},
199198
{
@@ -205,7 +204,7 @@
205204
},
206205
{
207206
"cell_type": "code",
208-
"execution_count": 5,
207+
"execution_count": null,
209208
"metadata": {},
210209
"outputs": [],
211210
"source": [
@@ -227,7 +226,7 @@
227226
},
228227
{
229228
"cell_type": "code",
230-
"execution_count": 6,
229+
"execution_count": null,
231230
"metadata": {},
232231
"outputs": [
233232
{
@@ -249,16 +248,16 @@
249248
"\n",
250249
"# Define the event callbacks\n",
251250
"# Refresh - the first full image we get back from the server\n",
252-
"stream.on_refresh(lambda event, item_stream : display_event(\"Refresh\", event))\n",
251+
"stream.on_refresh(lambda event, item_stream : display_event('Refresh', event))\n",
253252
"\n",
254253
"# Update - as and when field values change, we receive updates from the server and process the MRN data\n",
255-
"stream.on_update(lambda event, item_stream : process_mrn_update(\"Update\", event))\n",
254+
"stream.on_update(lambda event, item_stream : process_mrn_update(event))\n",
256255
"\n",
257256
"# Status - if data goes stale or item closes, we get a status message\n",
258-
"stream.on_status(lambda event, item_stream : display_event(\"Status\", event))\n",
257+
"stream.on_status(lambda event, item_stream : display_event('Status', event))\n",
259258
"\n",
260259
"# Other errors\n",
261-
"stream.on_error(lambda event, item_stream : display_event(\"Error\", event))"
260+
"stream.on_error(lambda event, item_stream : display_event('Error', event))"
262261
]
263262
},
264263
{
@@ -387,7 +386,7 @@
387386
},
388387
{
389388
"cell_type": "code",
390-
"execution_count": 8,
389+
"execution_count": null,
391390
"metadata": {},
392391
"outputs": [],
393392
"source": [
@@ -396,7 +395,7 @@
396395
" # Close the session\n",
397396
" ld.close_session() \n",
398397
"except Exception as ex:\n",
399-
" print(\"Error in close session: \" + str(ex))\n",
398+
" print(f'Error in close session: {str(ex)}')\n",
400399
" "
401400
]
402401
},
@@ -424,7 +423,7 @@
424423
"name": "python",
425424
"nbconvert_exporter": "python",
426425
"pygments_lexer": "ipython3",
427-
"version": "3.10.10"
426+
"version": "3.11.5"
428427
}
429428
},
430429
"nbformat": 4,

0 commit comments

Comments
 (0)