Jupyter notebooks
You can use the Modal client library in notebook environments like Jupyter! Just
import modal
and use as normal. You will likely need to use app.run
to create an ephemeral app to run your functions:
# Cell 1
import modal
app = modal.App()
@app.function()
def my_function(x):
...
# Cell 2
with modal.enable_output():
with app.run():
my_function.remote(42)
Known issues
Interactive shell and interactive functions are not supported.
These can only be run within a live terminal session, so they are not supported in notebooks.
If you encounter issues not documented above, try restarting the notebook kernel, as it may be in a broken state, which is common in notebook development.
If the issue persists, contact us in our Slack.
We are working on removing these known issues so that writing Modal applications in a notebook feels just like developing in regular Python modules and scripts.
Jupyter inside Modal
You can run Jupyter in Modal using the modal launch
command. For example:
$ modal launch jupyter --gpu a10g
That will start a Jupyter instance with an A10G GPU attached. You’ll be able to access the app with via a Modal Tunnel URL. Jupyter will stop running whenever you stop Modal call in your terminal.
See --help
for additional options.