Register multiple routes from multiple modules

Hello :wave: ,
I was trying to accomplish the following:
Say I have this folder structure:

.
├── appA.py
├── appB.py
└── main.py

I would like to use main as an entry point by calling the wave run main and
register two routes, /appA and /appB that are importing the functions in appA.py and appB.py respectively.
My main file:

# main.py
from h2o_wave import main, app, Q, ui, site, core
import appA, appB
app("/appA")(appA.serveA)
app("/appB")(appB.serveB)

my appA.py and appB.py content:

# appA.py
from h2o_wave import main, app, Q, ui, site, core

async def serveA(q: Q):
    q.page['main'] = ui.markdown_card(box='1 1 -1 -1', title='''
        This is app A served on /appA
    ''', content='Test')
    await q.page.save()
# appB.py
from h2o_wave import main, app, Q, ui, site, core

async def serveB(q: Q):
    q.page['main'] = ui.markdown_card(box='1 1 -1 -1', title='''
        This is app B served on /appB
    ''', content='Test')
    await q.page.save()

As a results I get only the first registered function appA.serveA on /appA available. Is it possible to do what I’m trying to do or is there a better way to register multiple apps on different routes with functions coming from different python modules?

There can be only one @app function registered for a given app process.

I would put @app('/appA') on serveA() and @app('/appB') on serveB(), and then run the two apps separately using wave run appA and wave run appB.

appA.py and appB.py can reuse code from shared modules.

Thanks, I see now.
What would you suggest to do in case of a dockerized application?
Creating sub processes like tour.py does?

To run multiple apps in the same container, I would follow this approach: Run multiple services in a container | Docker Documentation and run two Python processes using ./venv/bin/uvicorn appA:main and ./venv/bin/uvicorn appB:main.

I wouldn’t recommend following the approach in tour.py, since that’s an app whose purpose is to run other apps, and is super-hacky.

1 Like