Get help from the marimo community

Updated last month

How can we define a project's root directory?

At a glance

The community members are discussing how to set the project root and import modules in a Python project with a specific structure. The main points are:

1. The answer provided is to modify sys.path at the beginning of each notebook, but some tools expect or allow base directories to be specified in the pyproject.toml file.

2. One community member suggests making the processors module a package and doing an editable install, so they don't need to modify sys.path.

3. The community members discuss the tools that allow specifying base directories in the pyproject.toml file, and the potential use cases for integrating Jupyter notebooks more deeply into their workflows.

There is no explicitly marked answer in the comments.

For example, given
Plain Text
src/my_proj/processors/simple_processor.py
notebooks/nb1.py

I'd like to set the project root as src/proj and, from notebook nb1.py, import
Plain Text
from processors.simple_processor import SimpleProcessor
M
A
5 comments
If the answer is to modify sys.path at the beginning of every notebook, that's fine, but some tools expect/allow base directories to be specified in pyproject.toml
The answer is modify sys.path, if that's your project structure. I personally would make processors a package and do an editable install of it, so I didn't need to modify sys.path. But I understand you may have other constraints.
What tools are you thinking of that expect/allow base directories to be specified in the toml file?
I'd have to look at some old pyproject.tomls to find reasonable examples –

In general, other projects are installed as editable, but I would just point out, I wouldn't be surprised if there's a much larger cohort of users (compared to jupyter users, for example) who are interested in integrating marimo notebooks deeper into their workflows, such that the notebook is a component rather than a customer or a view.

For example, a data ingestion process that runs silently, when all is well, but still contains the narrative (visualizations, validations, etc.) somewhat frozen in time, which can be difficult to recreate in a comment block, especially with regard to statistics driven processes, which are subject to drift, etc.
Makes sense — enabling those types of workflows is a goal of ours. If you have a suggestion of how you’d like to specify paths, all ears.
Add a reply
Sign up and join the conversation on Discord