Dataquery — a syntax builder for screening with Eikon Data API

Jonathan Legrand
LSEG Developer Community
3 min readJun 28, 2023

Read Leonid Sopotnitskiys full article on the Developer Portal.

In this Medium article, we will use the new and improved Python RD Lib. (Refinitiv Data Library for Python) instead of its older version, EDAPI (the Eikon Data API), as per Leonid’s original article on the Developer Portal. For a full understanding of the dynamics at play, please read that article and its accompanying GitHub repo.

Have you ever used the Workspace Screener (e.g.: ICOSCRNR app), and wanted to be able to reproduce this screen programmatically, using Python? Maybe you had a screen like this, looking at all US public companies with ESG Scores:

Well, getting it in Python couldn’t be easier thanks to Chavalit Jintamalits article. As he shows, you can export the screen into excel with formulas:

You can then use the formula in Pytohn, with a few tweeks.

However, depending on your screen, you may need a lot of tweeks! And it can be dificult to know how to translate the function from Excel’s to Python’s. That’s where the dataquery come in. Please import the dataquery.py file in the same directory as where you want to run your Python (screener) code, and then simply import it in your code with the line:

from dataquery import *

Don’t forget the RD Lib.:

import refinitiv.data as rd
try: # The following libraries are not available in Codebook, thus this try loop
rd.open_session(
config_name="C:\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.config.json",
name="desktop.workspace")
except:
rd.open_session()

(I have my configuration file in the location ‘C:\Example.DataLibrary.Python-main\Configuration’, you may want to put it elsewhere. For more info on the RD Lib.’s cofig file, read this article.)

Now you can create queries without Excel or the Workspace Screener app! The dataquery functionsd are intuitive and easy to understand. I recreated the above screen like this:

query = SCREEN.express.universe(
Equity(active=True, public=True, primary=True)) \
.conditions(IN('TR.RegCountryCode', 'US'), FLOOR('TR.TRESGScore')) \
.currency('USD').query
query

‘SCREEN(U(IN(Equity(primary,public,active))), IN(TR.RegCountryCode,US), FLOOR(TR.TRESGScore), CURN=USD)’

rd.get_data(
query,
'TR.TotalRevenue')

If you have any questions about how to use this python file, don’t hesitate to ask on the Q&A Portal!

Reference:

Leonid Sopotnitskiy’s original article on the Developer Portal

Q&A Portal

dataquery.py

Chavalit Jintamalits article

Python RD Lib. (Refinitiv Data Library for Python)

EDAPI (the Eikon Data API)

accompanying GitHub repo.

Workspace

Screener

ICOSCRNR app

RD Lib.’s cofig file article

--

--