Skip to content

LSEG-API-Samples/Example.DataLibrary.Python.Docker

Repository files navigation

How to Run Data Library for Python in Docker

Overview

This project demonstrates how to run the LSEG Data Library for Python (aka Data Library version 2) inside a container. This means you can package the application and run it anywhere without worrying about installing Python or managing dependencies on your local machine.

What you'll learn:

  • How to containerize a Python application that accesses LSEG financial data
  • How to connect to LSEG's cloud platform (Platform Session) from within a container
  • How to build and run containers using Docker or Podman

Technology used:

  • Data Library for Python version 2.1.1
  • Python 3.12
  • Docker or Podman (containerization tools)

What You'll Need

Before you begin, make sure you have:

  1. LSEG Credentials: An account with access to the Delivery Platform (Data Platform) that includes Pricing and Historical Pricing permissions
    • Don't have credentials? Contact your LSEG representative for access
  2. Containerization Tool: Either Docker Desktop or Podman installed on your computer
  3. Internet Connection: Required to download packages and connect to LSEG services

About the Data Library for Python

The Data Library for Python is a powerful toolkit that gives you easy access to LSEG's vast collection of financial data and services. Think of it as a universal adapter that lets you access the same data whether you're working from:

  • Your desktop (Workspace application)
  • The cloud (Delivery Platform)
  • Real-time streaming services

Key benefits:

  • Write code once, use it across multiple platforms
  • Simple, consistent interface regardless of your data source
  • Available in Python, .NET, and TypeScript

Figure-1

The Data Library are available in the following programming languages:

Want to learn more? Check out these resources:

Why Use "Platform Session" for Containers?

The Data Library can connect to data in different ways:

  • Desktop Session: Requires the LSEG Workspace desktop application running on your computer
  • Platform Session: Connects directly to LSEG's Delivery Platform (aka Data Platform, RDP) on the Cloud. No desktop app needed.

For containerized applications, we use Platform Session because:

  1. Containers can't access the Workspace desktop applications running on your host computer
  2. Platform Session consumes data from cloud
  3. Your container can run anywhere with internet access

Understanding the Technical Setup

About the Dockerfile

Think of a Dockerfile as a recipe for building your application's container. This project uses a simple approach to:

  1. Start with a pre-made Python environment (Python 3.12)
  2. Install the required Python packages
  3. Copy your application files
  4. Set up the container to run your application automatically

Note about SSL certificates:

The use of --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --no-cache-dir command inside a Dockerfile is to avoid LSEG beloved Zscaler that blocks access to PyPI repository by default (don't ask me why).

The command bypass SSL certificate verification. If you need the SSL verification, please change Dockerfile's RUN commands to the following statements:

RUN pip install --upgrade pip && \
    pip install --no-cache-dir --user -r requirements.txt

Step-by-Step: Running Your Application

Follow these steps to build and run your containerized application. The examples use podman commands, but if you're using Docker, simply replace podman with docker.

Step 1: Download the Project

Download or unzip this project to a folder on your computer.

Step 2: Configure Your Credentials

  1. Open the lseg_data.config.json file in a text editor

  2. Add your LSEG credentials:

    "sessions": {
        "default": "platform.ldp",
        "platform": {
            "ldp": {
                "app-key": "YOUR APP KEY GOES HERE!",
                "username": "YOUR LDP LOGIN OR MACHINE GOES HERE!",
                "password": "YOUR LDP PASSWORD GOES HERE!",
                "signon_control":true
            },
            "ldpv2":{
                "client_id": "Service-ID (Client ID V2)",
                "client_secret": "Client Secret",
                "signon_control":true,
                "app-key": ""
            }
        }
    }
  3. Important: Choose the correct authentication version:

    • Version 1 (Machine-ID): Set "default" to "platform.ldp"
    • Version 2 (Service-ID): Set "default" to "platform.ldpv2"

Step 3: Build Your Container Image

  1. Open a command prompt or terminal

  2. Navigate to the project folder

  3. Run this command to build the container image:

    podman build -t ld_app .

    This process may take a few minutes as it downloads and installs everything needed.

  4. When complete, verify the image was created:

    podman images

    You should see ld_app in the list.

    figure-1

Step 4: Run Your Application

Start the container with this command:

podman run -it --name ld_app ld_app

Your application will now run and connect to LSEG's data platform!

figure-2

To stop the application: Press Ctrl+C

Step 5: Cleanup (Optional)

When you're done, you can remove the container and image:

Remove the container:

podman rm ld_app

figure-3

Remove the image:

podman rmi ld_app

figure-4

What if I am using Docker?

The project supports both Podman and Docker Containerization tool. I have tested the project with Docker and it works fine.

figure-5

figure-6

Additional Resources

Want to dive deeper? Here are some helpful resources:

For any questions related to this example or the LSEG Data Library, please use the Developer Community Q&A Forum.

About

Example of how to run Data Library for Python in Docker using Platform Session

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published