Import: Generated UI from any Python Function
Automatically generate UI's to import data from your enterprise's databases.
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:
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.
List[int]
A list of number inputs. Each input will be cast with the int function.
Dict[str, str]
A pair of string inputs.
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!
Examples
Using the List[int] data type to let users filter a dataframe to relevant rows.
import mitosheet
import pandas as pd
from typing import List
def get_fund_data(fund_ids: List[int]):
fund_performances = pd.DataFrame({
'Fund ID': [1,2,3,4,5,6,7,8,9],
'June Returns': [.1,.2,.3,.4,.5,.6,.7,.8,.9],
'July Returns': [.1,.2,.3,.4,.5,.6,.7,.8,.9]
})
# Filter the dataframe to only include the fund_ids set by the user
filtered_fund_data = fund_performances[fund_performances['Fund ID'].isin(fund_ids)]
return filtered_fund_data
mitosheet.sheet(importers=[get_fund_data])

Last updated
Was this helpful?