# API Reference

## The Spreadsheet Component

To display the Mito spreadsheet in a Streamlit application, use the following code:

```python
from mitosheet.streamlit.v1 import spreadsheet

# ... rest of your streamlit app

spreadsheet()
```

### Component API

{% code fullWidth="false" %}

```python
from mitosheet.streamlit.v1 import spreadsheet

spreadsheet(
    *args: , 
    import_folder: Optional[str]=None,
    df_names: Optional[List[str]]=None,
    sheet_functions: Optional[List[Callable]]=None, 
    importers: Optional[List[Callable]]=None, 
    code_options: Optional[CodeOptions]=None,
    column_definitions: Optional[List[ColumnDefinitions]]=None,
    return_type: Options[str]='default',
    default_editing_mode: Optional[Literal['cell', 'column']]=None,
    height: Optional[str]=None,
    key=None
) -> Tuple[Dict[str, pd.DataFrame], str]
```

{% endcode %}

<table data-full-width="true"><thead><tr><th width="239">Argument Name</th><th width="264.3333333333333">Type</th><th>Explanation</th></tr></thead><tbody><tr><td><code>*args</code></td><td><pre><code>Union[pd.DataFrame, str]
</code></pre></td><td>Pass any number of Pandas dataframes or paths to CSV files that will be displayed by in the Mito spreadsheet.</td></tr><tr><td><code>import_folder</code></td><td><pre><code>Optional[str]
</code></pre></td><td>A file path to a folder where users can import data from. Any subfolders will be available for navigation and importing within the Mito file browser.</td></tr><tr><td><code>df_names</code></td><td><pre><code>Optional[List[str]]
</code></pre></td><td>if you pass Pandas dataframes through the <code>args</code>, then optionally include the names of these dataframes in this list. This makes Mito generated code more correct.</td></tr><tr><td><code>sheet_functions</code></td><td><pre><code>Optional[List[Callable]]
</code></pre></td><td>Pass functions that are available as spreadsheet functions in the Mito spreadsheet. <a href="../how-to/interacting-with-your-data/bring-your-own-spreadsheet-functions">See more here. </a><em>(Mito Enterprise)</em></td></tr><tr><td><code>importers</code></td><td><pre><code>Optional[List[Callable]]
</code></pre></td><td>Pass custom data importers that get an auto-generated UI. <a href="../how-to/importing-data-to-mito/import-generated-ui-from-any-python-function">See more here. </a><em>(Mito Enterprise)</em></td></tr><tr><td><code>editors</code></td><td><pre><code>Optional[List[Callable]]
</code></pre></td><td>Pass Python functions that edit a dataframe to get an auto-generated Ui. <a href="https://docs.trymito.io/how-to/custom-editors-autogenerate-ui-from-any-function">See more here.</a> <em>(Mito Enterprise)</em></td></tr><tr><td><code>code_options</code></td><td><code>Optional[CodeOptions]</code></td><td>Pass a <code>CodeOptions</code> object to specify how the code should be generated. <a href="../how-to/code-options">See more here.</a> <em>(Mito Enterprise)</em></td></tr><tr><td><code>column_definitions</code></td><td><code>Optional[List[ColumnDefinitions]]=None</code></td><td>An optional list of <code>ColumnDefinitions</code> to specify conditional formats for a set of columns. See below for usage. <a href="api-reference/column-definitions">See more here</a>. <em>(Mito Enterprise)</em></td></tr><tr><td><code>key</code></td><td><pre><code>Optional[str]
</code></pre></td><td>An optional key that uniquely identifies this component. Necessary if you have multiple Mito <code>spreadsheet</code> displaying the same data.</td></tr><tr><td><code>return_type</code></td><td><code>Optional[str]</code></td><td>An optional string to identify what information you want from the <code>spreadsheet</code> function. See below for the options.</td></tr><tr><td><code>default_editing_mode</code></td><td><code>Optional[Literal['cell', 'column']]</code></td><td>Sets default formula editing behavior. Formulas will either default to editing the entire column, or the specific cell being edited. If not set, defaults to editing the entire column. <em>(Mito Enterprise)</em></td></tr><tr><td><code>height</code></td><td><code>Optional[str]</code></td><td>An optional string to specify the height in pixels that you want to use for the mitosheet. ie: "900px"</td></tr></tbody></table>

### Return Types

By default, the `spreadsheet` component returns:

```python
new_dfs, code = spreadsheet()
```

* `new_dfs`: a Python dictionary from dataframe name to dataframe object. There will be one entry for each tab in the Mito spreadsheet.
* `code`: a string that corresponds to the edits made by the user of the course of the Mito analysis.&#x20;

#### MitoAnalysis Return Type

To **easily rerun your analysis on new data,** return the [MitoAnalysis](https://docs.trymito.io/mito-for-streamlit/api-reference/runnableanalysis-class) class through the `return_type` parameter:

```python
analysis = spreadsheet(return_type='analysis')
```

#### Other return types

* `selection`: the current selected cells in the mitosheet
* `default_list`: similar to the default return type, but the dataframes are a list instead of a dictionary
* `dfs_dict` similar to the default return type, but only returns the dict without the code
* `code`: similar to the default return type, but only return the code
* `dfs_list`: returns a list of the dataframes generated by the analysis

## Examples

Below are examples of common uses of the Mito spreadsheet component in a streamlit application.

#### Empty Mito Spreadsheet

```python
from mitosheet.streamlit.v1 import spreadsheet

# Render an empty spreadsheet that allows users to import from the ./data folder
new_dfs, _ = spreadsheet(import_folder='./data')
```

#### Display a Dataframe for Editing

```python
import pandas as pd
from mitosheet.streamlit.v1 import spreadsheet

# Pass a single dataframe for editing
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
new_dfs, _ = spreadsheet(df, df_names=['df'])
new_df = list(new_dfs.values())[0]

# Note that multiple dataframes can be passed as well
# and each will appear as a tab in the Mito spreadsheet
new_dfs, _ = spreadsheet(df1, df2, df_names=['df1', 'df2'])

```

#### Display a CSV file for Editing

```python
from mitosheet.streamlit.v1 import spreadsheet

# Mito will automatically read this file into a dataframe
# and display it as a sheet tab
dfs, _ = spreadsheet('path-to-file.csv')
```

#### Displaying Mito generated code

```python
from mitosheet.streamlit.v1 import spreadsheet

# The second return value is Mito generated code
new_dfs, code = spreadsheet('path-to-file.csv')

# Display the code
st.code(code)
```
