Authenticating with a configuration file

By default, the Refinitiv Data Library for Python expects you to provide credentials in a configuration file named refinitiv-data.config.json.

At minimum, it must include your application key, as well as the username and password you use to access the Refinitiv web portal.

Start by copying and pasting the following snippet into a file named refinitiv-data.config.json. Replace the placeholder values with your credentials.

{
  "sessions": {
    "default": "platform.rdp",
    "platform": {
      "rdp": {
        "app-key": "YOUR APP KEY GOES HERE!",
        "username": "YOUR RDP LOGIN OR MACHINE GOES HERE!",
        "password": "YOUR RDP PASSWORD GOES HERE!"
      }
    }
  }
}

Note

A fuller example of all the configuration options available can be found in Refinitiv’s official documentation.

Unless you provide further instruction your Python script will expect the configuration file to be located in the same directory as the script you are running. Once the file is in place, you can import the library and open a session by running the following code:

import refinitiv.data as rd

rd.open_session()
/home/runner/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_access_layer/session.py:71:FutureWarning: 
You open a platform session using the default value of the signon_control parameter (signon_control=True).
In future library version v2.0, this default will be changed to False.
If you want to keep the same behavior as today, you will need to set the signon_control parameter to True either in the library configuration file
({'sessions':{'platform':{'your_session_name':{'signon_control':true}}}}) or in your code where you create the Platform Session.
These alternative options are already supported in the current version of the library.
<refinitiv.data.session.Definition object at 0x7f01d4908fd0 {name='rdp'}>

Verify the session is open by executing a query for the current price of Thomson Reuters stock. You should back a table of data.

rd.get_history('TRI.N')
TRI.N TRDPRC_1 HIGH_1 LOW_1 ACVOL_UNS OPEN_PRC BID ASK TRNOVR_UNS VWAP BLKCOUNT BLKVOLUM NUM_MOVES TRD_STATUS SALTIM
Date
2024-03-28 155.83 157.6 155.03 136750 156.17 155.69 155.77 21297952 155.7437 1 38347 1451 1 72600
2024-04-01 155.3 155.84 154.07 49537 155.84 155.24 155.25 7684388 155.1242 1 18664 783 1 72600
2024-04-02 152.73 154.26 152.12 74566 153.79 152.67 152.73 11394046 152.8048 1 23812 992 1 72600
2024-04-03 152.44 153.49 151.98 59196 152.08 152.36 152.44 9032983 152.5945 1 22021 839 1 72600
2024-04-04 152.15 153.71 151.31 144144 153.12 152.05 152.15 21929318 152.1348 1 89214 878 1 72600
2024-04-05 151.94 152.91 151.72 73655 151.76 151.93 152.0 11198767 152.0435 1 18916 901 1 72600
2024-04-08 153.97 154.2 152.25 58333 152.25 153.93 153.94 8971913 153.8051 1 16132 810 1 72600
2024-04-09 154.54 154.59 152.28 63643 154.18 154.54 154.59 9813995 154.2038 1 13254 725 1 72600
2024-04-10 153.17 153.69 152.14 75560 153.35 153.17 153.21 11577309 153.2201 1 25115 807 1 72600
2024-04-11 154.55 154.66 151.89 80012 153.93 154.54 154.55 12323739 154.0236 1 16442 979 1 72600
2024-04-12 152.38 154.02 152.18 114429 153.27 152.3 152.31 17457709 152.5637 1 14924 1395 1 72600
2024-04-15 152.55 154.71 152.41 72123 153.47 152.62 152.63 11035400 153.0081 1 23057 1018 1 72600
2024-04-16 152.29 153.15 151.88 70968 152.74 152.29 152.41 10818902 152.4476 1 19346 882 1 72600
2024-04-17 152.85 153.72 151.56 67852 153.19 152.85 152.9 10371667 152.8572 1 17920 844 1 72600
2024-04-18 150.79 153.05 150.42 91115 153.05 150.76 150.77 13784004 151.2814 1 17998 1203 1 72600
2024-04-19 150.22 151.63 149.55 89600 150.79 150.22 150.33 13481424 150.4623 1 16898 1359 1 72600
2024-04-22 152.99 153.99 151.14 74409 151.2 152.99 153.0 11372959 152.8439 1 19596 927 1 72600
2024-04-23 153.59 154.61 153.28 72989 153.9 153.54 153.64 11219982 153.7216 1 19619 846 1 72600
2024-04-24 152.63 155.12 152.16 70534 153.56 152.63 152.71 10792980 153.0181 1 22383 801 1 72600
2024-04-25 152.57 153.11 150.07 77710 151.05 152.57 152.58 11843493 152.4063 1 17395 918 1 72600

The library expects you to close your session when you’re finished. You can do so by running the following code:

rd.close_session()

Specifying a configuration file

If you want to store your configuration file in a different location, you can specify its path when you open a session.

For example, if you gave your configuration file with a shorter name and stored it in a subdirectory named config, you could open a session by running something like the following:

rd.open_session(config_name="./config/refinitiv.json")