marimo-learn
Utilities for use in marimo notebooks.
ConceptMapWidget
Bases: AnyWidget
A concept mapping widget where students draw labeled directed edges between concepts.
Students select a relationship term then click two concept nodes to connect them. Concept nodes can be dragged to rearrange the layout.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
The question or prompt shown above the map |
concepts |
list
|
List of concept names (nodes) |
terms |
list
|
List of relationship terms that can label edges |
correct_edges |
list
|
List of dicts with 'from', 'to', 'label' keys |
value |
dict
|
State with 'edges', 'score', 'total', and 'correct' keys |
Source code in src/marimo_learn/concept_map.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
FlashcardWidget
Bases: AnyWidget
A flashcard widget with self-reported spaced repetition.
Students flip cards to reveal the answer, then rate themselves (Got it / Almost / No). Cards rated "Almost" or "No" are re-inserted into the queue; the deck is complete when all cards are rated "Got it".
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
Optional heading shown above the deck |
cards |
list
|
List of dicts with 'front' and 'back' keys |
shuffle |
bool
|
Whether to shuffle the deck initially |
value |
dict
|
State with 'results' (per-card ratings/attempts) and 'complete' |
Source code in src/marimo_learn/flashcard.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
LabelingWidget
Bases: AnyWidget
A text labeling widget where students drag numbered labels to text lines.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
The question text to display |
labels |
list
|
List of label texts (shown on left) |
text_lines |
list
|
List of text lines to be labeled (shown on right) |
correct_labels |
dict
|
Mapping of line indices to lists of correct label indices |
value |
dict
|
Current state with 'placed_labels', 'score', 'total', and 'correct' keys |
Source code in src/marimo_learn/labeling.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
__init__(question, labels, text_lines, correct_labels, lang='en', **kwargs)
Initialize a labeling widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question text |
required |
labels
|
list[str]
|
List of label texts (e.g., ["Variable declaration", "Function call", "Loop"]) |
required |
text_lines
|
list[str]
|
List of text lines to be labeled (e.g., code lines, sentences) |
required |
correct_labels
|
dict
|
Dict mapping line index to list of correct label indices Example: {0: [0, 1], 2: [2]} means line 0 should have labels 0 and 1, line 2 should have label 2 |
required |
Source code in src/marimo_learn/labeling.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
MatchingWidget
Bases: AnyWidget
A matching question widget where students pair items from two columns using drag-and-drop.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
The question text to display |
left |
list
|
Items in the left column |
right |
list
|
Items in the right column |
correct_matches |
dict
|
Mapping of left column indices to right column indices |
value |
dict
|
Current state with 'matches', 'correct', and 'score' keys |
Source code in src/marimo_learn/matching.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__(question, left, right, correct_matches, lang='en', **kwargs)
Initialize a matching widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question text |
required |
left
|
list[str]
|
Items in the left column |
required |
right
|
list[str]
|
Items in the right column |
required |
correct_matches
|
dict
|
Dict mapping left indices to right indices (e.g., {0: 2, 1: 0, 2: 1}) |
required |
Source code in src/marimo_learn/matching.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
MultipleChoiceWidget
Bases: AnyWidget
A multiple choice question widget.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
The question text to display |
options |
list
|
List of answer options |
correct_answer |
int
|
Index of the correct answer (0-based) |
explanation |
str
|
Optional explanation text shown after answering |
value |
dict
|
Current state with 'selected', 'correct', and 'answered' keys |
Source code in src/marimo_learn/multiple_choice.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__(question, options, correct_answer, explanation='', lang='en', **kwargs)
Initialize a multiple choice widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question text |
required |
options
|
list[str]
|
List of answer options |
required |
correct_answer
|
int
|
Index of the correct answer (0-based) |
required |
explanation
|
str
|
Optional explanation text |
''
|
Source code in src/marimo_learn/multiple_choice.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
OrderingWidget
Bases: AnyWidget
An ordering question widget where students arrange items in sequence using drag-and-drop.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
str
|
The question text to display |
items |
list
|
Items in the correct order |
shuffle |
bool
|
Whether to shuffle items initially |
value |
dict
|
Current state with 'order' and 'correct' keys |
Source code in src/marimo_learn/ordering.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__init__(question, items, shuffle=True, lang='en', **kwargs)
Initialize an ordering widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question text |
required |
items
|
list[str]
|
Items in the correct order |
required |
shuffle
|
bool
|
Whether to shuffle items initially (default: True) |
True
|
Source code in src/marimo_learn/ordering.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
is_pyodide()
Is this notebook running in pyodide?
Source code in src/marimo_learn/utilities.py
8 9 10 11 | |
localize_file(filepath)
Download a file from the 'public' directory, returning the local path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
path relative to 'public' directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
local file path |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if remote file not found |
Source code in src/marimo_learn/utilities.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |