Views:

Lumipy is a Python library that makes it easy to use Luminesce as part of the Python data science ecosystem, in particular Pandas and Jupyter.

Once installed and authenticated, and providing end users have sufficient access control permissions, they can interact with Luminesce using their familiar Python programming environment. See all tools and interfaces to Luminesce.

Installing Lumipy

For a minimal installation, run the following command:

pip3 install dve-lumipy-preview

For a full installation, including the ability to create your own providers and interact with LUSID Drive, run the following commands in sequence:

pip3 install "dve-lumipy-preview[providers]"
python3 -m lumipy.provider setup --secrets=/path/to/secrets.json

See below for information about secrets.json.

For an installation which only installs the parts of Lumipy you specifically require, run the following command to download Lumipy without dependencies:

pip3 install dve-lumipy-preview --no-dependencies

You can then install the parts you require, for example:

pip3 install pandas finbourne-sdk-utilities>=0.0.10 luminesce-sdk-preview

Authenticating to Lumipy

As with any FINBOURNE SDK, you must obtain an API access token.

If you have not done so before, follow steps 1 and 2 in this tutorial to create a service user account and application, and generate a client secret. Then, follow these instructions to create a local secrets.json file, swapping <password> for your actual LUSID account password and replacing this JSON key/value pair:

"apiUrl": "https//<your-domain>.lusid.com/api"

with this one:

"lumiApiUrl": "https//<your-domain>.lusid.com/honeycomb"

...where <your-domain> is your unique LUSID domain name, for example acme.lusid.com.

Note: As an alternative to a local file, you can follow these instructions to set environment variables, replacing FBN_LUSID_API_URL with FBN_LUMI_API_URL and appending honeycomb to the exported URL instead of api.

You must pass the file location of secrets.json to either the client or the atlas object (see below). Note the API access token returned by Okta is valid for one hour.

Sending a SQL query directly to Luminesce

The simplest way to work with Lumipy is to use the client object to send a Luminesce SQL query directly to Luminesce.

For example, to use the Lusid.Instrument.Equity provider to retrieve the first five equity instruments mastered in LUSID as a Pandas dataframe:

import lumipy as lm
client = lm.get_client(api_secrets_filename = '/path/to/secrets.json')
df = client.run('select * from lusid.instrument.equity where Scope = \'default\' limit 5')

Scripting queries using Python

The most powerful way to work with Lumipy is to use the atlas object to create a hub for exploring providers and scripting queries using Python instead of SQL.

For example, to use the Lusid.Instrument.Equity provider to retrieve the first five equity instruments mastered in LUSID as a Pandas dataframe:

import lumipy as lm
atlas = lm.get_atlas(api_secrets_filename = '/path/to/secrets.json')
instr_provider = atlas.lusid_instrument() 
query = instr_provider.select('*').limit(5)
df = query.go()

To upsert equity instruments to LUSID using the Lusid.Instrument.Equity.Writer provider, you might:

  1. Read data into Pandas from a CSV file:
    import lumipy as lm
    import pandas as pd
    instr_df = pd.read_csv("data.csv", keep_default_na = False)
  2. Rename dataframe columns to align with expected provider column names, and add a column specifying an instrument scope:
    instr_df.rename(columns = {'Security': 'DisplayName', 'Internal_id': 'ClientInternal', 'Currency': 'DomCcy'}, inplace = True)
    instr_df['Scope'] = 'MyProtectedInstrumentScope'
  3. Convert the dataframe to a table variable in preparation for upserting to LUSID:
    tv = lm.from_pandas(instr_df)
  4. Upsert to LUSID, showing the response to retrieve the LUIDs and check for errors:
    w = atlas.lusid_instrument_equity_writer(to_write = tv)
    q = w.select('^')
    q.go()

Getting more information

Read the User Guide. Note this is 23 pages in total, not all of it shown at once; keep clicking the More Pages button:


You can also work through these Jupyter Notebook tutorials.

Note these statistical custom functions are designed to be used with Lumipy.