LUSID SDK for Python

2.3.100 · active · verified Fri Apr 17

The `lusid-sdk` is the official Python SDK for interacting with the LUSID API, a cloud-native investment data platform. It enables programmatic management of portfolios, holdings, transactions, reference data, and various other financial data entities within the LUSID ecosystem. The SDK is actively maintained by FINBOURNE, with frequent releases often several times a month to reflect API updates and feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ApiClientFactory`, authenticate using environment variables (supporting both Personal Access Token and OAuth2 Client Credentials flows), and make a simple call to list portfolios. Ensure the necessary LUSID environment variables are set before running.

import os
from lusid_sdk.utilities import ApiClientFactory
from lusid_sdk.api import PortfoliosApi

# Configure environment variables for LUSID authentication.
# These can be set in your shell or via a .env file.
# Example for Personal Access Token (PAT):
# export LUSID_FBN_TOKEN='your_finbourne_token'
# export LUSID_API_URL='https://lusid.finbourne.com/api'
# export LUSID_APP_NAME='my-python-app'
#
# Example for OAuth 2.0 Client Credentials:
# export LUSID_CLIENT_ID='your_client_id'
# export LUSID_CLIENT_SECRET='your_client_secret'
# export LUSID_TOKEN_URL='https://identity.finbourne.com/oauth/token'
# export LUSID_API_URL='https://lusid.finbourne.com/api'
# export LUSID_APP_NAME='my-python-app'

try:
    # Create an ApiClientFactory instance. It picks up config from environment variables.
    # For LUSID_FBN_TOKEN, you would use: ApiClientFactory()
    # For OAuth, you might need to pass details if not in env vars, but env vars are preferred.
    api_factory = ApiClientFactory()

    # Get a specific API client, e.g., for portfolios
    portfolios_api: PortfoliosApi = api_factory.build(PortfoliosApi)

    # List all portfolios
    paginated_response = portfolios_api.list_portfolios(
        limit=5,
        scope='default'
    )

    print(f"Successfully connected to LUSID. Found {paginated_response.paging.total_items} portfolios.")
    for portfolio in paginated_response.values:
        print(f"- {portfolio.display_name} ({portfolio.scope}/{portfolio.code})")

except Exception as e:
    print(f"An error occurred: {e}")
    if "401 Unauthorized" in str(e):
        print("Please check your LUSID authentication details (LUSID_FBN_TOKEN or OAuth credentials).")
    elif "Missing configuration" in str(e):
        print("Ensure LUSID_API_URL and authentication environment variables are set.")

view raw JSON →