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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b475ce165942731a5d3c3e2bc48fb470b29c8d97f6bd759ab04db2eb7abf695
|
|
| MD5 |
821e786efd8652dd9c90a52ee32c624a
|
|
| BLAKE2b-256 |
29c46b254ca8466b9c64173fa77b8ee09c66aa06498f06ed3ddbb23cd2d19c30
|
Provenance
The following attestation bundles were made for lkapi-0.3.0.tar.gz:
Publisher:
release.yml on lightkeeper/lkapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lkapi-0.3.0.tar.gz -
Subject digest:
2b475ce165942731a5d3c3e2bc48fb470b29c8d97f6bd759ab04db2eb7abf695 - Sigstore transparency entry: 2212526490
- Sigstore integration time:
-
Permalink:
lightkeeper/lkapi@f3d905cb1924e225ccd16cb193fd9939063620e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lightkeeper
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f3d905cb1924e225ccd16cb193fd9939063620e9 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eaecdb934f50f457fb5bddd41daef0a25c77e5486e9e30461993eb2fbc00882
|
|
| MD5 |
6115e47ca68a5504e5e13b0e166dbdcd
|
|
| BLAKE2b-256 |
b40e4b6f67b433bb3ad9c19bcc4e7338a6a3defe1a151b87c23050828746c3fe
|
Provenance
The following attestation bundles were made for lkapi-0.3.0-py3-none-any.whl:
Publisher:
release.yml on lightkeeper/lkapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lkapi-0.3.0-py3-none-any.whl -
Subject digest:
9eaecdb934f50f457fb5bddd41daef0a25c77e5486e9e30461993eb2fbc00882 - Sigstore transparency entry: 2212526517
- Sigstore integration time:
-
Permalink:
lightkeeper/lkapi@f3d905cb1924e225ccd16cb193fd9939063620e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lightkeeper
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f3d905cb1924e225ccd16cb193fd9939063620e9 -
Trigger Event:
workflow_dispatch
-
Statement type: