{"id":9911,"library":"lusid-sdk","title":"LUSID SDK for Python","description":"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.","status":"active","version":"2.3.100","language":"en","source_language":"en","source_url":"https://github.com/finbourne/lusid-sdk-python","tags":["financial","api","fintech","investment","data platform"],"install":[{"cmd":"pip install lusid-sdk","lang":"bash","label":"Install `lusid-sdk`"}],"dependencies":[],"imports":[{"note":"While `Configuration` and `ApiClient` exist, `ApiClientFactory` is the recommended and more robust way to set up and manage API clients, especially for authentication.","wrong":"from lusid_sdk.configuration import Configuration","symbol":"ApiClientFactory","correct":"from lusid_sdk.utilities import ApiClientFactory"},{"note":"All API clients follow this import pattern, e.g., `TransactionsApi`, `QuotesApi`.","symbol":"PortfoliosApi","correct":"from lusid_sdk.api import PortfoliosApi"}],"quickstart":{"code":"import os\nfrom lusid_sdk.utilities import ApiClientFactory\nfrom lusid_sdk.api import PortfoliosApi\n\n# Configure environment variables for LUSID authentication.\n# These can be set in your shell or via a .env file.\n# Example for Personal Access Token (PAT):\n# export LUSID_FBN_TOKEN='your_finbourne_token'\n# export LUSID_API_URL='https://lusid.finbourne.com/api'\n# export LUSID_APP_NAME='my-python-app'\n#\n# Example for OAuth 2.0 Client Credentials:\n# export LUSID_CLIENT_ID='your_client_id'\n# export LUSID_CLIENT_SECRET='your_client_secret'\n# export LUSID_TOKEN_URL='https://identity.finbourne.com/oauth/token'\n# export LUSID_API_URL='https://lusid.finbourne.com/api'\n# export LUSID_APP_NAME='my-python-app'\n\ntry:\n    # Create an ApiClientFactory instance. It picks up config from environment variables.\n    # For LUSID_FBN_TOKEN, you would use: ApiClientFactory()\n    # For OAuth, you might need to pass details if not in env vars, but env vars are preferred.\n    api_factory = ApiClientFactory()\n\n    # Get a specific API client, e.g., for portfolios\n    portfolios_api: PortfoliosApi = api_factory.build(PortfoliosApi)\n\n    # List all portfolios\n    paginated_response = portfolios_api.list_portfolios(\n        limit=5,\n        scope='default'\n    )\n\n    print(f\"Successfully connected to LUSID. Found {paginated_response.paging.total_items} portfolios.\")\n    for portfolio in paginated_response.values:\n        print(f\"- {portfolio.display_name} ({portfolio.scope}/{portfolio.code})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    if \"401 Unauthorized\" in str(e):\n        print(\"Please check your LUSID authentication details (LUSID_FBN_TOKEN or OAuth credentials).\")\n    elif \"Missing configuration\" in str(e):\n        print(\"Ensure LUSID_API_URL and authentication environment variables are set.\")","lang":"python","description":"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."},"warnings":[{"fix":"Always prefer `from lusid_sdk.utilities import ApiClientFactory` and use `api_factory.build(YourApiClass)` to get API clients.","message":"The recommended authentication and client creation mechanism is `ApiClientFactory`. Direct instantiation of `Configuration` and `ApiClient` objects from `lusid_sdk.configuration` and `lusid_sdk.api_client` is still possible but less robust for managing multiple API clients or complex authentication flows.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Check the `list_` method documentation for `get_all_` alternatives or manually handle pagination using `response.paging.next_page` and `limit`/`page` parameters.","message":"Many LUSID API list methods return paginated results. Directly accessing `response.values` will only give the first page. For comprehensive results, you need to iterate through pages or use the SDK's built-in `get_all` helper methods (if available for the specific API endpoint).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly update `lusid-sdk` to the latest version (`pip install --upgrade lusid-sdk`) to ensure compatibility with the LUSID API and access to the newest features.","message":"LUSID is a rapidly evolving platform. The SDK is frequently updated to reflect changes in the underlying LUSID API (new endpoints, modified models, deprecations). Using an outdated SDK version can lead to `AttributeError` for missing fields/methods or unexpected API behaviour.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate existing code to use `ApiClientFactory` for all API client instantiation and configuration. Refer to the official SDK documentation for migration guides.","message":"Major version 2.0.0 introduced significant changes to the SDK's internal structure and recommended usage patterns, primarily around how API clients are instantiated and configured. Older code using direct `ApiClient` and `Configuration` setup may break or behave unexpectedly without modification.","severity":"breaking","affected_versions":"From 2.0.0 onwards"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure all necessary LUSID environment variables (e.g., `LUSID_API_URL`, `LUSID_APP_NAME`, and appropriate authentication credentials) are correctly set in your environment or provided directly to the `ApiClientFactory`.","cause":"The `ApiClientFactory` could not find required environment variables like `LUSID_API_URL` or authentication credentials (e.g., `LUSID_FBN_TOKEN`, `LUSID_CLIENT_ID`, `LUSID_CLIENT_SECRET`).","error":"ValueError: Missing configuration for API client factory: LUSID_API_URL"},{"fix":"Verify that your `LUSID_FBN_TOKEN` or OAuth2 client credentials (`LUSID_CLIENT_ID`, `LUSID_CLIENT_SECRET`, `LUSID_TOKEN_URL`) are correct and have the necessary permissions. Also, check that `LUSID_API_URL` is correct.","cause":"The SDK failed to authenticate with the LUSID API, indicating incorrect or expired credentials.","error":"finbourne.lusid.sdk.ApiException: (401) Unauthorized"},{"fix":"You must first build an API client from the factory for the specific service you want to interact with. For example, `portfolios_api = api_factory.build(PortfoliosApi)` and then call `portfolios_api.list_portfolios()`.","cause":"You are attempting to call an API method directly on the `ApiClientFactory` instance, instead of on a specific API client built by the factory.","error":"AttributeError: 'ApiClientFactory' object has no attribute 'list_portfolios'"}]}