Check LSEG Data Library for Python Usage Limits Remaining

Raksina Samasiri
Developer Advocate Developer Advocate
Jirapongse Phuriphanvichai
Developer Advocate Developer Advocate

Introduction

Have you wondered how much usage you have left until it's exceed the limit? To prevent the user from experiencing issues due to abnormal or excessive usage, the LSEG Data Library applies usage limits. You can find the official guidelines in Documentation | Devportal

Currently, you can check your Data Library usage by enabling debug logging in the Workspace Application and inspecting the HTTP response headers. This article walks you through the process, including how to use monkey-patching to print out response headers directly from your Python code.

Note: I'm using LSEG Data Library for Python version 2.1.1 here

Step 1: Enable Debug Logging in LSEG Workspace

1. Open the Configuration Manager in your LSEG Workspace Application.

2. Navigate to the Logs page under the Advanced section.

3. Set the Trace Level to Debug, then click Apply (see screenshot below)
Note: Setting the trace level to Debug may impact system performance. Use this level only when troubleshooting or monitoring usage.

4. Click OK to apply the configuration and Restart LSEG Workspace to activate the changes.

Step 2: Configure Logging in Your Python Script

You can set the log level to debug either in your configuration file or directly in your code. Here’s the example configuration file: (see more detail and example of configuration file here)

    	
            

{

    "logs": {

        "level": "debug",

        "transports": {

            "console": {

                "enabled": true

            },

            "file": {

                "enabled": true,

                "name": "lseg-data-lib.log"

            }

        }

    },

    "sessions": {

        "default": "desktop.workspace",

        "desktop": {

            "workspace": {

                "app-key": "<YOUR APP KEY>"

            }

        }

    }

}

And here's how to do it in-line:

    	
            

import lseg.data as ld

 

config = ld.get_config()

config.set_param("logs.transports.console.enabled", True)

# config.set_param("logs.transports.file.enabled", True)  # Uncomment to log to file

config.set_param("logs.level", "debug")

 

ld.open_session()

Step 3: Monkey-Patch the Data Library to Log HTTP Response Headers

To print out the HTTP response headers (which often include usage and limit information), you can monkey-patch the request method in the HTTPService class:

    	
            

import lseg.data._core.session.http_service as http_service

from httpx import Response

 

# Save original method if needed

original_request = http_service.HTTPService.request

 

# Define your custom version

def custom_request(self, request):

    response: Response = self._client.send(request)

    print(f"HTTP Response id {request.id} {response.headers}")

    return response

 

# Monkey-patch the method

http_service.HTTPService.request = custom_request

Step 4: Run Your Data Retrieval Code

Now, when you run your Data Library functions to retrieve data, the HTTP response headers—including any limit or usage information—will be printed in your console log (or log file, depending on your configuration).

Step 5: Check Detailed Logs in Workspace

For more detailed information about your API usage and limits:

  • Go to the Workspace Logs folder. The Full Path to it can be found in Logs section of Configuration Manager
  • Open the most recently created sub-folder named like Desktop.<date>.<time>.p<process-ID>.
  • Look for the file named node-sxs.<date>.p<process-ID>.log.
  • Search for the lines that contains [DEBUG] DP Client::Limiter

Here, you can find additional details about your requests and any limit-related messages.

Conclusion

By enabling debug logging and monkey-patching the LSEG Data Library, you can easily monitor your API usage and remaining limits in real time. This approach helps you stay within your quotas and troubleshoot issues more effectively.

The sample Jupyter Notebook file for this article can be found in the top right section of this article.

Request Free Trial

Help & Support

Already a customer?

Office locations

Contact LSEG near you