Custom Spreadsheet Functions
Create your own spreadsheet functions and share them with your entire organization.
This is a Mito Enterprise feature. Upgrade to extend your spreadsheet with additional spreadsheet functions.
The Mito spreadsheet is built to be extensible to your teams use case. Mito users or infrastructure administrators can the data analysis capabilities of their team by incorporating custom Python functions directly into the sheet.
Bringing your own functions enables organizations to maintain their proprietary algorithms, calculations, and domain-specific knowledge right within Mito Spreadsheet. Stop your internal Python code from rotting on the shelf, and get it to end users in the most intuitive interface -- a spreadsheet.
How to Write Custom Spreadsheet Functions
Let's say that we want to use a custom spreadsheet function called ADD_ONE
that adds 1 to the input number.
Custom spreadsheet functions must:
Have a fully capitalized function name
Support the correct input types
Optionally, spreadsheet functions can use a a docstring to configure spreadsheet syntax hints.
Custom functions must be fully capitalized
Custom spreadsheet functions are required to have fully upercase names.
If you have my_function
you wish to add, simply wrap it in a wrapper to use it in the Mitosheet.
Custom functions must support the correct input types
When writing formulas in a Mito spreadsheet, there are a few ways to reference other pieces of data in the spreadsheet. Let's consider each reference type, and the data type you receive in return.
Imagine we're writing a formula on the dataframe df
, and we write formulas in example formula. The passed type to the function will be:
For the first two references types of single-cell references, the passed through type will be a pd.Series
. For the entire column reference, a pd.DataFrame
will be passed. Finially, the RollingRange
is a Mito-specific object that has the following interface.
Rolling Range Object
A rolling range is a helper object that is passed to sheet functions when the user references a range within the sheet. For example, consider how the following references transpile:
To support range references in your custom functions, you can use the RollingRange.apply
function, which has the following type:
Displaying syntax hints inside of Mito
Displaying syntax support to the user inside of the Mito spreadsheet makes it easy for them to use your custom functions.
If you want to add syntax support for your custom functions, you can do so by writing a docstring for your function that adheres to the following structure. Mito will automatically detect the docstring and convert it into useful syntax support.
This will display the syntax support:
How to add spreadsheet functions to the Mitosheet
There are two ways to make the custom functions accessible in Mito:
Passing the spreadsheet functions as a parameters
In Jupyter, you can make spreadsheet functions accessible using the following code:
If you're using Streamlit, you can instead pass the spreadsheet functions as a paramter to the spreadsheet component.
Setting an environment variable
If your spreadsheet functions are importable from a .py file, you can set the following environment variables, to make those spreadsheet functions accessible in Mito.
Examples of Sheet Functions
To see how sheet functions are implemented in practice, you can view example sheet functions here:
Last updated