Skip to content

Installing the Python Agent

Installing the Python agent

The Lightrun agent is at the core of the Lightrun platform. It's the component that enables you to add information during runtime, without the need for redeployments or restarts.

Before running the agent, it must be installed on the server and its credentials declared either inside the application code, in the agent.config file, or as environment variables entered at the command line.

Version Support

The instructions below apply to Python v2.7 and Python v3.6 onwards If you're interested in support for other versions, please reach out and let us know!

Windows Support

The Python agent currently is not supported on Windows.

Instructions

  1. Install the python agent by running python -m pip install lightrun.

  2. Import Lightrun inside your main function, by adding the following code at the beginning of the function.

    try:
         import lightrun
         lightrun.enable(company="<COMPANY_NAME>" , company_key="<COMPANY_SECRET>")
    except ImportError as e:
         print("Error importing Lightrun: ", e)
    

    Note: Add the server_url parameter when using Lightrun on-prem.

    Alternatively, when running your Python application from the command line, you can pass the <COMPANY_NAME> and <COMPANY_SECRET> parameters as environment variables.

    python -m lightrun --server_url=https://app.lightrun.com/company/ --company <COMPANY_NAME> --company_secret=<COMPANY_SECRET> -- app.py
    
  3. Run the application as you normally would; for example, python app.py.

Important

Lightrun actions in Python must only be applied to a function before it is called. Actions inserted within a function while it is executing take effect only once the function is exited and called again.

Getting Company Details

You can get <COMPANY_NAME> and <COMPANY_SECRET> by logging into the the Management Portal and inspecting the Download the Agent section.


Last update: January 18, 2022