A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: minor function fileformat edits (#4576)
Akshay Agrawalc590c8007043
diff --git a/docs/guides/reusing_functions.md b/docs/guides/reusing_functions.mdindex 3624f9e077..37799e8abf 100644--- a/docs/guides/reusing_functions.md+++ b/docs/guides/reusing_functions.md@@ -1,9 +1,9 @@-# Importing Functions and Classes Defined in Marimo Notebooks+# Importing functions and classes defined in notebooksYou can import top-level functions and classes defined in a marimo notebookinto other Python scripts or notebooks using normal Python syntax, as long asyour definitions satisfy the simple criteria described on this page. This makes-your notebook code modular and reusable, testable, and easier to edit in text editors+your notebook code reusable, testable, and easier to edit in text editorsof your choice.## Overview@@ -40,7 +40,7 @@ In another script or notebookfrom my_notebook import my_utility_function, DataProcessor```-## Creating a top-level function+## Creating a top-level function or class### 1. Create a setup cell@@ -51,9 +51,8 @@ classes will need:import numpy as np```-To add a setup cell in the editor, use the General menu and select "Add setup cell" (💠).--Setup cells are guaranteed to run before all other cells.+To add a setup cell in the editor, open the notebook menu and select "Add setup cell".+(The setup cell is guaranteed to run before other cells.)### 2. Define your function@@ -86,9 +85,9 @@ def calculate_statistics(data):Under the hood, marimo decorates top-level functions with `@app.function`,which you can use to define your own top-level functions if you are editing a-notebook file directly.+notebook file directly. Top-level classes are decorated with `@app.class_definition`.-### 3. Reuse your definitions+### 3. Import into other Python filesNow you can import your function in other notebooks or Python scripts:@@ -101,23 +100,6 @@ stats = calculate_statistics(data)print(stats)```-## Class definitions--Classes are also serialized top-level if they meet the [criteria](overview).-Under the hood, marimo decorates top-level classes with-`@app.class_definition`, which you can use if you are editing your notebook-file directly:--```python[email protected]_definition-class DataProcessor:- def __init__(self, data):- self.data = data-- def normalize(self):- return (self.data - np.mean(self.data)) / np.std(self.data)-```-## Best practices- Use setup cells for immediate, widely used imports@@ -137,7 +119,6 @@ class DataProcessor:## Learn more-For more detailed information about marimo's file format and features, check-out our [documentation on using your own-editor](https://docs.marimo.io/guides/editor_features/watching/) or view our-[file format tutorial](https://marimo.app/?slug=8n55fd).+For more on marimo's file format, check out our [documentation on using your+own editor](../guides/editor_features/watching.md) or view+our [file format tutorial](https://links.marimo.app/tutorial-fileformat).diff --git a/marimo/_tutorials/fileformat.py b/marimo/_tutorials/fileformat.pyindex cfbd7802a8..df44722f37 100644--- a/marimo/_tutorials/fileformat.py+++ b/marimo/_tutorials/fileformat.py@@ -2,7 +2,7 @@import marimo-__generated_with = "0.12.8"+__generated_with = "0.12.10"app = marimo.App()with app.setup:@@ -147,7 +147,7 @@ def _(mo):In the generated code, there is a function for each cell. The argumentsof the function are the cell's refs , and its returned variables are- its defs.+ its defs that are referenced by other cells.For example, the code@@ -160,7 +160,7 @@ def _(mo):```says that the cell takes as input a variable called `mo`, and it creates- a global variable called `text`.+ a global variable called `text` (that is read by another cell).In contrast, the code