Accessing static data from Python in bokeh serve

I have a bokeh serve directory app.

I can serve images by putting them into static/img/myimage.png and using this path e.g. in TOOLTIPS as an @path.

However, I would also need to read some external data into the backend. As I understand it, the static folder gets hosted to the frontend (html) and is not accessible for the Python backend, is that correct? e.g. I cannot do os.listdir("my_app/static/my_data")?

I know that I can use absolute paths to load the data into Python, however, this means that I need to change the path everytime the users changes the location of the bokeh app. Is there any way to use relative paths in the backend? (Sorry if this terminology is slightly incorrect)

I might have found a solution for this. I am using the following code in main.py:

try:
    my_data_path = os.path.join(os.path.dirname(__file__), "static", "data")
except NameError:
    print("__file__ not defined. Is this running in interactive IPython mode?")

If there is a better way, let me know.

@Thomas that seems OK. There’s no public API to report the location of the static files to the app code (not for any particular reason, just no one has ever asked about it before). It could conceivably
be exposed though curdoc() somehow, but I’m not sure when it would get prioritized (happy to help anyone else work on a PR tho)