Import: Generated UI from any Python Function

Automatically generate UI's to import data from your enterprise's databases.

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 can augment the data analysis capabilities of their team by incorporating existing Python functions into their sheet.

Namely, any function that returns a dataframe can be exposed to a Mito user within a spreadsheet, automatically. This allows less-technical teammates to benefit from all the Python code written by the programmers in your org, without these less-technical folks needing to learn to code! Also, it requires no additional UI building by you!

See also: bring your own spreadsheet functions.

How to add a custom importer into Mito

Imagine we have a function that takes some inputs and returns a dataframe:

def get_loan_data(date: str, include_duplicates: bool) -> pd.DataFrame:
    ...

You can simply pass this to the mitosheet call in a notebook or Streamlit:

# In a notebook
mitosheet.sheet(importers=[get_loan_data])

# In Streamlit
spreadsheet(importers=[get_loan_data])

Then, this function will be accessible in the Import dropdown within the mitosheet, where an option for Get Loan Data will appear.

Selecting this option will open a UI this is automatically generated for this function:

Adding a custom importer to Mito in Streamlit

Simply use the importers parameter to the spreadsheet component in Streamlit. See more in the Streamlit API reference.

Supported Types

For Mito to automatically generate the correct UI for your function, it should have Python types attached to it. The currently supported types:

TypeUI Element

str

A string input.

int

A number input. The input will be cast with the int function.

float

A number input. The input will be cast with the float function.

bool

A toggle. The input will be cast with the bool function.

pd.DataFrame

A dataframe select, allowing users to select from the dataframes in Mito.

ColumnHeader

A column select, referencing the nearest pd.DataFrame type. See below.

unlabeled

An input that will be evaluated with the Python eval function.

Understanding the ColumnHeader type

The ColumnHeader type can be imported from the Mito extension package, and tells Mito to generate a UI that allows a user to select a specific column from the preceding dataframe in the auto-generated UI.

import pandas as pd
from mitosheet.extensions.v1 import ColumnHeader

def extension_function(df: pd.DataFrame, column_header: ColumnHeader):
    # insert function here

Notably, any ColumnHeader parameter will error if it is not preceeded by a pd.DataFrame parameter -- as it is unclear which dataframe the ColumnHeader is referencing!

Last updated