Skip to main content

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.10
  • requests
  • pandas

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

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.2.0.tar.gz (11.3 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.2.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

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

Hashes for lkapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 81d52955f3292ec2ae16326dcb6690110efb91e99b24d74dc4c1fbe84be331ce
MD5 3f48d6168850edcce97e5e39676651da
BLAKE2b-256 af23e28913d490d238394318893b2898110b33d546a57ffae0bed291ac589cc6

See more details on using hashes here.

Provenance

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

Publisher: publish.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.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

Hashes for lkapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35ada5779cf75ba189de20d33bd405ee64f1dfc1733ddab07746709385860507
MD5 cc00ee0d30c00f7e994594682c71210f
BLAKE2b-256 518fd4ad48ad85295a7016b408afea022c603783b1d217ab2d94a54d0f698683

See more details on using hashes here.

Provenance

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

Publisher: publish.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