Notebooks support

Known issues

Modal can be used in a notebook environment, such as Jupyter Notebooks, but there are some limitations to be aware of.

Modal functions and app must be defined and executed within a single notebook cell.

Currently you cannot spread your Modal functions and stub.run() app execution across multiple cells. Code from other cells can be referred to, but all @stub.function() decorations should be in a single cell.

Modal functions can only be called remotely. Invoking the wrapped function locally does not work.

@stub.function()
def f():
    return "hello"

with stub.run():
    assert "hello" == f.call()  # remote call works ✔️
    f()  # raises error in notebook ⚠️

Interactive shell and interactive functions are not yet supported. Notebook environments require special handling of REPL terminal functionality which is not yet implemented.

If you encounter issues not documented above, first check your Modal client version is >=0.49.2142. Also, try restarting the notebook kernel, as the kernel state may be in a broken state, a common problem in notebook development.

If the issue persists, contact us in Slack.

We are working on removing these limitations so that writing Modal applications in a notebook feels just like developing in regular Python modules and scripts.

Further examples