Python SDK

Prev Next

The LUSID Python SDK provides convenient access to the LUSID REST API in Python 3.11+ environments.

Note: Supporting applications in the FINBOURNE platform (such as Drive, Scheduler and Luminesce) have their own Python SDKs.

You can install the latest version of the LUSID Python SDK from PyPi using your preferred package manager, for example:

pip install lusid-sdk
pip install finbourne-sdk-utils         <- Optional useful utilities

Note the following:

  • Python 3.11 or later is required.

  • If you are upgrading from an earlier major version, read these instructions.

  • We strongly recommend pinning a SDK to an exact version to control when you take updates and make your builds repeatable.

  • Alternatively, you can download the source by cloning the Github repo. If you do, note the main branch may not always correspond to the latest REST API version.

To authenticate for the first time, you must generate a client ID and secret and store them with the credentials of a valid LUSID user as either environment variables or in a secrets file. The LUSID Python SDK uses these credentials to obtain a short-lived access token from FINBOURNE's identity provider (Okta) on demand, which it can then refresh periodically. More information.

Documentation with code samples is available in Github for both endpoints and models, or as a searchable package on Readthedocs (the content is the same).

Hello world

This example authenticates to the synchronous version of the SDK using a secrets file and calls the appropriate SDK method to invoke the ListInstruments API:

# Setup:
import lusid, pprint
from lusidjam import RefreshingToken
from lusid.extensions import (
    SyncApiClientFactory,
    ArgsConfigurationLoader,
    SecretsFileConfigurationLoader
)

# Assemble config:
secrets_path = "/path/to/secrets.json"
config_loaders=[
    ArgsConfigurationLoader(access_token = RefreshingToken(), app_name = "LusidJupyterNotebook"),
    SecretsFileConfigurationLoader(secrets_path) 
]

# Instantiate and authenticate:
api_factory = SyncApiClientFactory(config_loaders=config_loaders)

# Build Instruments API and list first instrument:
try:
    instruments_api = api_factory.build(lusid.InstrumentsApi)
    response = instruments_api.list_instruments(limit=1)
    pprint.pprint(response.to_dict()["values"])
except lusid.exceptions.ApiException as e:
    print(e)