Flexible interface for defining functions with marimo UI inputs
Project description
marimo-functions
Flexible interface for defining functions with marimo UI inputs
What is a "Marimo Function"
When running analysis in marimo, it is common to have a set of inputs
which are all mapped as inputs to a particular function.
The marimo-functions library provides a simple framework for
implementing this pattern of user interaction.
The MarimoFunction class has an inputs attribute which maps
keyword arguments to marimo UI elements.
The type attribute of each input specifies the UI element,
and all of the remaining kwargs are passed to the constructor.
The run() method then takes the kwargs provided by the user
and runs any method that consumes them appropriately.
For example:
from marimo_functions import MarimoFunction
from sklearn.manifold import TSNE as SKTSNE
class TSNE(MarimoFunction):
"""
A class representing a t-SNE (t-distributed Stochastic Neighbor Embedding) function.
"""
inputs = {
"n_components": {
"type": "number",
"label": "Number of components",
"value": 2,
"start": 1,
"step": 1
},
"perplexity": {
"type": "number",
"label": "Perplexity",
"value": 30,
"start": 5,
"stop": 50,
"step": 1
},
"early_exaggeration": {
"type": "number",
"label": "Early exaggeration",
"value": 12.0,
"start": 1.0,
"stop": 100.0,
"step": 0.1
},
"random_state": {
"type": "number",
"label": "Random State",
"value": 0
}
}
name = "t-SNE"
description = "T-distributed Stochastic Neighbor Embedding."
@classmethod
def run(cls, **kwargs) -> SKTSNE:
return SKTSNE(**kwargs)
Using a Function
To make use of a function in marimo, simply prompt the user for the inputs:
# func: MarimoFunction
inputs = func.prompt()
inputs
Note that by using
inputsas the last line in the marimo cell, it is presented as a UI element to the user.
And then run the function using the values provided by the user:
output = func.run(**inputs.value)
Picking a Function
In addition to the single function, this library provides a mechanism for selecting a function of interest from a dropdown menu.
from marimo_functions import PickFunction
selected_function = (
PickFunction(
functions=[
FunctionA,
FunctionB,
FunctionC,
FunctionD,
FunctionE
]
)
.prompt(
label="Select a function",
value="Function A"
)
)
selected_function
The function selected by the user can be populated by the value attribute.
func = selected_function.value
# Display the description of the function
mo.md(func.description)
Interactive Example
To run a marimo notebook displaying this functionality:
- Set up the local environment (
uv sync) - Launch the notebook (
uv run marimo edit example.py)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file marimo_functions-0.2.0.tar.gz.
File metadata
- Download URL: marimo_functions-0.2.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a45596ed6ada63c294c90f088598ea572bd9d6c218019f1f3a5d4339daef184d
|
|
| MD5 |
2842092b5679e4141742f8f51dd00cc6
|
|
| BLAKE2b-256 |
e98148afb5ccb0d30ef368fd865927e337397d01ea2306f41208e42889d58e57
|
Provenance
The following attestation bundles were made for marimo_functions-0.2.0.tar.gz:
Publisher:
release.yaml on FredHutch/marimo-functions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marimo_functions-0.2.0.tar.gz -
Subject digest:
a45596ed6ada63c294c90f088598ea572bd9d6c218019f1f3a5d4339daef184d - Sigstore transparency entry: 699969016
- Sigstore integration time:
-
Permalink:
FredHutch/marimo-functions@da295566a60047a5ee549f2efeff6c201f82faaa -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/FredHutch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@da295566a60047a5ee549f2efeff6c201f82faaa -
Trigger Event:
push
-
Statement type:
File details
Details for the file marimo_functions-0.2.0-py3-none-any.whl.
File metadata
- Download URL: marimo_functions-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d5fdaedd30405413b025333a586bca85d7bb64cfb4a17a41b91cfaaf9f5aa4e
|
|
| MD5 |
613800125fc1e926804124a32774a246
|
|
| BLAKE2b-256 |
d6f043fc948cac33eb0bf8e619aa5826fea5ce6dda2ef2786f811d73ad8fd511
|
Provenance
The following attestation bundles were made for marimo_functions-0.2.0-py3-none-any.whl:
Publisher:
release.yaml on FredHutch/marimo-functions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marimo_functions-0.2.0-py3-none-any.whl -
Subject digest:
4d5fdaedd30405413b025333a586bca85d7bb64cfb4a17a41b91cfaaf9f5aa4e - Sigstore transparency entry: 699969020
- Sigstore integration time:
-
Permalink:
FredHutch/marimo-functions@da295566a60047a5ee549f2efeff6c201f82faaa -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/FredHutch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@da295566a60047a5ee549f2efeff6c201f82faaa -
Trigger Event:
push
-
Statement type: