Author:
The LSEG Data Library (LD Lib) for Python is extremely powerful and gives you access to an ever expanding universe of financial data. To connect to the London Stock Exchange’s (LSEG’s) databases using the LD Lib., however, you will need to start a connection session to authenticate yourself to LSEG’s services; and that’s where the configuration file comes into play.
You can find a lot of information on connection sessions in EX-4.01.01-Sessions.ipynb, but in this article, I will focus more on the configuration file and the process by which it is used in creating sessions.
Configuration File
A quick word on the configuration file. You can find it here, and it contains all the information about the session you may want to create. You need to enter this information, namely :
- your App Key (which is necessary)
- your Login Username (which is not necessary)
- your Password (which is not necessary)
- your preference for default session, “platform” or “desktop”. More about these two session types can be found here, but all you need to know for this article is that the “desktop” session necessitates the Workspace/Eikon Desktop Application to be running on the machine where you run your code, and the “platform” one does not, but instead necessitates the ‘Login Username’ and ‘Password’ to be entered in the configuration file.
It may be that you did not create or use such a configuration file, in which case, if you are running the Workspace/Eikon Desktop Application (on the machine where you run your code), this information will be retrieved from the desktop application.
Sessions
There are two sessions, the “platform” and “desktop” sessions, with aforementioned characteristics. You can specify the preferable session with the text/string “platform.ldp” or “desktop.workspace” in the configuration file itself:
"sessions": {
"default": "desktop.workspace",
With the platform.ldp session, the library establishes the connection to the Data Platform on Cloud. However, with the desktop.workspace session, the library retrieves the data via the desktop application (Eikon or Workspace) running on the same machine so you need to run the desktop application on the same machine to use the desktop.workspace session. The permission may be different between the platform.ldp session and the desktop.workspace session. You can contact your account representative to verify the permission.
or in-line, in your Python code:
import lseg.data as ld
ld.open_session(name="desktop.workspace")
In-line preference takes precedence over the configuration file’s when it is specified.
If you have the Workspace or Eikon Desktop Application running on the machine where you run your code, you can simply run the below to create a session authentifying yourself to LSEG’s services:
ld.open_session()
But what is happening in the background?
The LD Lib. is created to search for configuration files that includes information such as your App Key, which are basically your username and password put together. (The App Key does not actually include your username and password, but it works as such, in effect, without any privacy issues.) It searches for configuration files in a specific order that can be checked with
for i in ld._configure.get_config()._configs:
print(i._config)
The order in question is:
1st: In-Line Path
You can specify the path to your configuration file in-line, as such:
import lseg.data as ld
ld.open_session(
config_name="C:/Example.DataLibrary.Python-main/Configuration/lseg-data.config.json")
Note that you can specify both the `config_name` and `name` here:
import lseg.data as ld
ld.open_session(
name="desktop.session",
config_name="C:/Example.DataLibrary.Python-main/Configuration/lseg-data.config.json")
2nd: In Your Code’s Directory
Wherever you are running your code on your PC (Personal Computer), you can put your configuration file there and the Data Library. will look for it there 2nd.
E.g.: if I am running a .ipynb Python file (i.e.: a Jupyter Notebook) in the directory “C:\”, I can put my configuration file in that same directory (“C:\”) and make sure that it is named correctly (i.e.: “lseg-data.config.json”). If I did not specify the path of my configuration file in-line, in my Python code, then the Data Library will use it to create a session.
3rd: In Your User’s Directory
E.g.: on my Windows PC, it’s in “C:\Users\John”. For you, it will be similar, something like “C:\Users\YourComputerUsernameHere”. In that path, I can find the configuration file named “lseg-data.config.json”.
4th: Desktop Application Specification
If you have the Workspace or Eikon Desktop Application running on the machine where you run your code, then the Data Library. will look, in last place, for configuration details from the Desktop Application; in which case a configuration file is not needed.
Example configuration setting
To change the value of http request-timeout configuration. The following configuration can be added into the configuration file.
{
"http": {
"request-timeout": 60
},
"logs": {
...
}
...
}
Or adding in-line code as below
ld.get_config()["http.request-timeout"] = 60
Conclusion
As you can see, the configuration file is essential, and you need to know where it lies to make sure that the correct credentials are being used.
Don't hesitate to read more on the Data Library.'s documentation here.