Python client code to work with the Lightkeeper API
Project description
lkapi
This repo providers example client code to work with the Lightkeeper API in python.
Access to the Lightkeeper API is handled via the OAuth2 client credentials flow.
If you'd like to know more about API access to your existing Lightkeeper environment, or have any enqiuries about working with Lightkeeper, please contact us.
Usage
Prior to running any of those commands, you'll be provided with a client_id, and client_secret from Lightkeeper. These credentials are required to make requests against your Lightkeeper environment.
Installation
This repo provides sample code that relies on:
python>3.10requestspandas
You can use the package manager pip to install these to your current python environment.
pip install requirements.txt
There's also support for more modern tools like poetry via pyproject.toml or uv via the lockfile.
uv sync
uv run python your_script.py
Usage
Prior to using the API, you will need to get a client_id, and client_secret from Lightkeeper. These credentials are required to make requests against your Lightkeeper environment.
In a longer term development or production environment, you can set the environment variables or in secure credential storage if the keyring python module is installed.
import lkapi.credential as lkcredential
# get a long-lived credential manager which will store to the keyring if available or environment variables otherwise
credential_manager = lkcredential.get_credential_manager(url="https://YOUR-LIGHTKEEPER-ENVIRONMENT.COM")
credential_manager.set_secret('CLIENT_ID_XXXXXX', 'CLIENT_SECRET_XXXX')
The credential manager provides a base class that can be extended to provide custom credential storage mechanisms.
The python client can be imported and run with stored credentials or by directly passing credentials.
import lkapi.client as lkapi
lkapi.get_grid_data(
url="https://YOUR-LIGHTKEEPER-ENVIRONMENT.COM/lightstation/api/reports/query/layout/Portfolio_Grid__user@lightkeeper.com/v1?bd=YYYYMMDD&ed=YYYYMMDD&focus=PORT&rollup=ROLLUP",
username="CLIENT_ID_XXXXXX", password="CLIENT_SECRET_XXXXXXX")
The return format defaults to a dictionary of information. If you would like to work with the raw response object you can set the argument debug=True in the make_api_request call.
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.
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.2.0.tar.gz.
File metadata
- Download URL: lkapi-0.2.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d52955f3292ec2ae16326dcb6690110efb91e99b24d74dc4c1fbe84be331ce
|
|
| MD5 |
3f48d6168850edcce97e5e39676651da
|
|
| BLAKE2b-256 |
af23e28913d490d238394318893b2898110b33d546a57ffae0bed291ac589cc6
|
Provenance
The following attestation bundles were made for lkapi-0.2.0.tar.gz:
Publisher:
publish.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.2.0.tar.gz -
Subject digest:
81d52955f3292ec2ae16326dcb6690110efb91e99b24d74dc4c1fbe84be331ce - Sigstore transparency entry: 741189054
- Sigstore integration time:
-
Permalink:
lightkeeper/lkapi@938bf0913cfa061b3740924acc76fdb4e1bf9513 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/lightkeeper
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@938bf0913cfa061b3740924acc76fdb4e1bf9513 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lkapi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lkapi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ada5779cf75ba189de20d33bd405ee64f1dfc1733ddab07746709385860507
|
|
| MD5 |
cc00ee0d30c00f7e994594682c71210f
|
|
| BLAKE2b-256 |
518fd4ad48ad85295a7016b408afea022c603783b1d217ab2d94a54d0f698683
|
Provenance
The following attestation bundles were made for lkapi-0.2.0-py3-none-any.whl:
Publisher:
publish.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.2.0-py3-none-any.whl -
Subject digest:
35ada5779cf75ba189de20d33bd405ee64f1dfc1733ddab07746709385860507 - Sigstore transparency entry: 741189066
- Sigstore integration time:
-
Permalink:
lightkeeper/lkapi@938bf0913cfa061b3740924acc76fdb4e1bf9513 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/lightkeeper
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@938bf0913cfa061b3740924acc76fdb4e1bf9513 -
Trigger Event:
release
-
Statement type: