Skip to content

A wrapper around marimo to convert Python files to marimo's format and live reload.

License

Notifications You must be signed in to change notification settings

adityasz/marimow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

marimoW

CI

Note

Only works on Linux; signal handling on macOS is different and I don't have a Mac. You can open a pull request with a fix: See src/lib.rs:run_marimo.

A marimo Wrapper.

Because

# %%

x = 1

# %%

print(x)

is easier to deal with than

@app.cell()
def _():
    x = 1


@app.cell()
def _():
    print(x)  # the type checker hates this too!
  • Convert Python scripts having cell delimiters (e.g., # %%; see config) into marimo's format:

    $ marimow convert notebook.py output.py
  • Edit a python file in any editor and marimoW will convert it to marimo's format on every write, so that it can live reload it in the browser frontend.

    $ marimow edit [OPTIONS] notebook.py

    This is equivalent to marimo edit --watch [OPTIONS] .marimow_cache/notebook.py, where .marimow_cache/notebook.py is in marimo's format.

Tip

marimo can autorun cells.

Note

marimo handles data dependencies automatically when the output is opened in marimo (see marimo docs), so it is not necessary to add them to function signatures or return statements.

To really hardcode them to the notebook, just open the output in marimo's web UI and save it there.

Installation

$ cargo install --git https://github.com/adityasz/marimow

Format

  • The cell delimiter can be configured in the config file.

  • The first cell is the setup cell:

    import numpy as np
    
    # %%
    
    x = np.array([1, 2, 3])

    gets converted to

    import marimo
    
    app = marimo.App()
    
    with app.setup:
        import numpy as np
    
    
    @app.cell
    def _():
        x = np.array([1, 2, 3])
    
    
    if __name__ == "__main__":
        app.run()
  • If you don't want a setup cell, keep the first cell blank:

    # Each `# %%` starts a new cell.
    #
    # Cells only containing whitespaces and comments are ignored (there are better
    # ways to add text to a marimo notebook than to add a cell with comments).
    # %%
    
    x = np.array([1, 2, 3])  # comments are preserved
    
    # %% everything after the cell delimiter is ignored
    
    print(x)

    gets converted to

    import marimo
    
    app = marimo.App()
    
    
    @app.cell
    def _():
        x = np.array([1, 2, 3])  # comments are preserved
    
    
    @app.cell
    def _():
        print(x)
    
    
    if __name__ == "__main__":
        app.run()

Note

marimoW indents everything in a cell by 4 spaces to put it in the body of @app.cell def _():. This does not affect multiline strings: The @app.cell decorator probably handles this correctly as the string length remains unchanged.

A multiline string having the delimiter in the beginning of a line will cause issues, but the delimiter is configurable, so it is up to the user. Zed preview 0.193.3's REPL also does not take care of this (and their delimiter can't be changed), despite having a parse tree of the file (for syntax highlighting).

Config

marimoW loads its config from ${XDG_CONFIG_HOME:-$HOME/.config/marimow}/marimow/config.toml.

The default config is

cache_dir = ".marimow_cache"
cell_delimiter = "# %%"
debounce_duration = 50 # milliseconds

Note

Note that if the cache directory is set to ${XDG_CACHE_HOME:-$HOME/.cache}/marimow, marimo does not autorun cells. (This may be a bug in marimo.) Thus, the default is .marimow_cache in the directory where marimoW is executed (which unfortunately means one more .gitignore entry).

About

A wrapper around marimo to convert Python files to marimo's format and live reload.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published