Installing or upgrading to v2 Python SDKs

Prev Next

You can install or upgrade to v2 of the following packages:

  • LUSID Python SDK

  • Other Python SDKs in the FINBOURNE platform, for example for Drive, Scheduler and Luminesce.

Note you must upgrade all SDKs used in a particular process to v2 at the same time. For example, a process that uses both the Scheduler and Drive SDKs must either use v1 of both SDKs or v2 of both SDKs; mixing major versions leads to dependency conflicts.

Installation

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

pip install lusid-sdk

Note the following:

  • Python 3.11 or later is required.

  • 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.

Preview SDKs

This release discontinues publishing the LUSID Preview SDK, instead adding the Experimental and Beta lifecycle APIs to the LUSID SDK. Note that making requests to Experimental and Beta APIs requires additional licences; for more details please contact support.

Changes to extensions packages

v1 lusid.utilities package has been renamed as lusid.extensions. The package now supports asynchronous requests using the asyncio library and makes loading configuration more configurable and readable:

  • You can now build an asynchronous client using the ApiClientFactory. To close connections after use, we recommend making requests within a context using a with statement.

    from lusid import ApiClientFactory, ApplicationMetadataApi
    api_client_factory = ApiClientFactory()
    async with api_client_factory:
        api_instance = api_client_factory.build(ApplicationMetadataApi)
  • You can now pass in a list of configuration loaders to ApiClientFactory or SyncApiClientFactory. We currently provide loaders for reading API configuration from environment variables, a secrets file or keyword arguments. Read more on authenticating to LUSID with the LUSID SDK. For example:

    from lusidjam import RefreshingToken
    from lusid import (
        SyncApiClientFactory,
        ApplicationMetadataApi,
        EnvironmentVariablesConfigurationLoader,
        SecretsFileConfigurationLoader,
        ArgsConfigurationLoader
    )
    config_loaders = [
        EnvironmentVariablesConfigurationLoader(),
        SecretsFileConfigurationLoader(secrets_path="secrets.json"),
        ArgsConfigurationLoader(access_token = RefreshingToken(), app_name = "LusidPython")
    ]
    api_client_factory = SyncApiClientFactory(config_loaders=config_loaders)
    api_instance = api_factory.build(ApplicationMetadataApi)

    Note the following:

    • Configuration loaders each return a dictionary of configuration keys and values. When keys are found by multiple configuration loaders, the last configuration loader to read the key overrides previous loaders.

    • Custom configuration loaders must implement the load_config method described in the configuration loader protocol.

Model arguments must be named

v2 of the LUSID Python SDK uses Pydantic to perform runtime type checking on model objects. The v2 upgrade removes positional argument support; model arguments must now be explicitly named.

For example:

## v1 of the SDK...
python_version = 'some_version' 
api_response = api_instance.get_excel_addin(python_version)

## ...might change as follows for v2 of the SDK to make the key/value pairs explicit:
python_version = 'some_version' 
api_response = await api_instance.get_excel_addin(version=python_version) 

Function arguments are type checked

In v2, models are more strict with argument types, and calling a function with incorrect types now throws a validation error. The error message shows you which fields need their values updating to meet the type check requirements.

For example:

 2 validation errors for Model 
 is_required 
     Field required [type=missing, input_value={'list_of_ints': ['1', 2,...ew York'}, 'gt_int': 21}, input_type=dict] 
 gt_int 
     Input should be greater than 42 [type=greater_than, input_value=21, input_type=int] 

Hello world

This example authenticates to the synchronous version of the SDK using a secrets file and invokes 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)

FINBOURNE SDK Utils replaces LUSID Python Tools

LUSID Python Tools is only available for use with v1 of the LUSID Python SDK. For v2 SDKs, FINBOURNE SDK Utils is introduced as a replacement for LUSID Python Tools.

FINBOURNE SDK Utils contains a set of utility functions for interacting with the v2 LUSID Python SDKs. The package includes all of the capabilities of LUSID Python Tools, in addition to the changes and improvements listed here. Users may need to update their code to reflect the changes.

You can install FINBOURNE SDK Utils for the LUSID Python SDK using the following pip command:

pip install finbourne-sdk-utils

Installing v1 of the LUSID Python SDK

Please note v1 of the LUSID Python SDK is now discontinued, but if you do need to install it for any reason then two packages are published:

  • lusid-sdk contains only APIs with a lifecycle status of Production or Early Access. You can install it using the following pip command:

    pip install lusid-sdk<2
  • lusid-sdk-preview contains additional APIs with a lifecycle status of Experimental or Beta. You can install it using the following pip command:

    pip install lusid-sdk-preview<2