Skip to main content

Python client code to work with the Lightkeeper API

Project description

lkapi

The Python client for the Lightkeeper Web API. It handles the OAuth2 client credentials flow, secure credential storage, and returns API data as pandas data frames.

If you'd like to know more about API access to your existing Lightkeeper environment, or have any enquiries about working with Lightkeeper, please contact us.

Installation

Requires python>=3.10.

pip install lkapi

For development on this repo, use uv from the python/ directory:

uv sync
uv run --group dev pytest

Usage

Prior to using the API, you will need a client_id and client_secret from Lightkeeper. These credentials are required to make requests against your Lightkeeper environment.

The quickest start is to copy a url from the Lightkeeper UI (Grid > Api Routes) and pass credentials directly:

import lkapi

frames = lkapi.get_grid_data(
    url="https://YOUR-ENVIRONMENT.lightkeeperhq.com/lightstation/api/reports/query/layout/YOUR_GRID/v2?focus=PORT&rollup=ISSUER&bd=20250101&ed=20250131",
    username="YOUR_CLIENT_ID",
    password="YOUR_CLIENT_SECRET",
)

The keys in the returned dictionary are:

  • request: Details about the request made including endpoint and parameters.
  • portfolio: Details on the portfolio the data was requested for including available dates and data update times.
  • rollup: A data frame of information summarized at the rollup level (e.g. one row per rollup).
  • time: A data frame of information summarized at the time level (e.g. one row per time period). If data is grouped in the view it will be one row per time period per group.
  • total: The total values. If data is grouped in the view it will be one row per group.

If you would like to work with the raw response object instead, set debug=True in the get_grid_data call.

Stored credentials

In a longer term development or production environment, store credentials once in secure credential storage (via the keyring python module if installed) or environment variables, rather than passing them in code.

import lkapi

# a long-lived credential manager which stores to the keyring if available or environment variables otherwise
credential_manager = lkapi.get_credential_manager(url="https://YOUR-ENVIRONMENT.lightkeeperhq.com")
credential_manager.set_secret('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET')

The CredentialManager base class can be extended to provide custom credential storage mechanisms.

With credentials stored, requests can be built from components instead of a copied url or sourced from the API source information found in the Grid:

import lkapi

frames = lkapi.get_grid_data(
    grid="YOUR_LAYOUT_ID",
    environment="YOUR-ENVIRONMENT",
    portfolio="LKP_YOUR_PORTFOLIO__PORT",
    rollup="ISSUER",
    begin_date="20250101",
    end_date="20250131",
)

Contributing

If you have any suggestions or requests regarding examples, features or additional languages for clients, please submit an issue to this repository or reach out to Lightkeeper support.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lkapi-0.3.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lkapi-0.3.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file lkapi-0.3.0.tar.gz.

File metadata

  • Download URL: lkapi-0.3.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lkapi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2b475ce165942731a5d3c3e2bc48fb470b29c8d97f6bd759ab04db2eb7abf695
MD5 821e786efd8652dd9c90a52ee32c624a
BLAKE2b-256 29c46b254ca8466b9c64173fa77b8ee09c66aa06498f06ed3ddbb23cd2d19c30

See more details on using hashes here.

Provenance

The following attestation bundles were made for lkapi-0.3.0.tar.gz:

Publisher: release.yml on lightkeeper/lkapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lkapi-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lkapi-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lkapi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9eaecdb934f50f457fb5bddd41daef0a25c77e5486e9e30461993eb2fbc00882
MD5 6115e47ca68a5504e5e13b0e166dbdcd
BLAKE2b-256 b40e4b6f67b433bb3ad9c19bcc4e7338a6a3defe1a151b87c23050828746c3fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for lkapi-0.3.0-py3-none-any.whl:

Publisher: release.yml on lightkeeper/lkapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page