docs/guides/scripts.md
You can run marimo notebooks as scripts at the command line, just like any other Python script. For example,
python my_marimo_notebook.py
Running a notebook as a script is useful when your notebook has side-effects, like writing to disk. Print statements and other console outputs will show up in your terminal.
marimo notebooks can also double as importable modules, providing libraries of functions and classes that you can reuse in other programs:
from my_notebook import my_function
Read our guide on reusable functions for details.
!!! tip "Check before running"
Before running a notebook as a script, you can use marimo's linter to check for issues that might prevent execution:
```bash
marimo check my_marimo_notebook.py
```
See the [Lint Rules](lint_rules/index.md) guide for more information about marimo's linting system.
!!! note "Saving notebook outputs"
To run as a script while also saving HTML of the notebook outputs, use
```bash
marimo export html notebook.py -o notebook.html
```
You can also pass command-line arguments to your notebook during export.
Separate these args from the command with two dashes:
```bash
marimo export html notebook.py -o notebook.html -- -arg value
```
Exporting to other formats, such as ipynb, is also possible:
```bash
marimo export ipynb notebook.py -o notebook.ipynb -- -arg value
```
When run as a script, you can access your notebook's command-line arguments
through sys.argv, just like any other Python program. This also
means you can declare your notebook's command-line arguments using Python
libraries like argparse
and simple-parsing.
These examples shows how to conditionally assign values to variables based on command-line arguments when running as a script, and use default values when running as a notebook.
/// marimo-embed-file filepath: examples/running_as_a_script/sharing_arguments.py ///
/// marimo-embed-file filepath: examples/running_as_a_script/with_simple_parsing.py ///
marimo notebooks are Python files, so any scheduler that runs Python scripts can run marimo notebooks. This includes cron, Airflow, Prefect, and other tools. You can pass variables from the command line and reuse functions from notebooks in other jobs as well.
Run notebooks on a schedule with GitHub Actions. This example assumes inline dependencies:
name: Run marimo notebook daily
on:
schedule:
- cron: '0 9 * * *'
jobs:
run-marimo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v7
- run: uv run path/to/notebook.py