-
-
Notifications
You must be signed in to change notification settings - Fork 327
Using idom from FastAPI #650
-
I have a couple of questions regarding the use of idom from FastAPI?
It seems to be giving me the following error:
RuntimeError: asyncio.run() cannot be called from a running event loop
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py:384: RuntimeWarning: coroutine 'Server.serve' was never awaited
I don't know how to get it to work with FastAPI.
Any help is greatly appreciated.
Cheers,
Dev.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 11 replies
-
Do you think you could post the code sample that's producing this error? Also, have you checked out the documentation on running IDOM? There's a number of code samples there. If any of them fail you should post back here with the code and associated tracebacks you're seeing.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi Mark/Ryan,
Would you happen to have a small app to kickstart an idom web app with a simple authentication?
Beta Was this translation helpful? Give feedback.
All reactions
-
Authentication will depend entirely on your web framework and is not handled by IDOM. To oversimplify, the job of IDOM is simply to plop things on the web page. Everything else is handled by your web framework of choice.
For example, I personally use IDOM with Django, so I use the Django authentication system.
I personally don't use FastAPI so I'm not entirely sure what the land of FastAPI user authentication looks like. I'm going to assume, based on the name FastAPI, it's probably not designed for convenient user authentication.
On the flip side, I'm confident user authentication would be fairly standard in Flask.
Beta Was this translation helpful? Give feedback.
All reactions
-
@seeclearvision just to follow up, have you managed to get things working?
Beta Was this translation helpful? Give feedback.
All reactions
-
I'd try taking a look at this example here. The only difference for FastAPI is in the import of the server implementation and how you actually run the server.
# main.py from fastapi import FastAPI from idom import component, html from idom.server.fastapi import PerClientStateServer, Config app = FastAPI() @component def IdomView(): return html.h1("This is an IDOM App") PerClientStateServer(IdomView, app=app, config=Config(url_prefix="app"))
Then in your terminal run:
uvicorn main:app
In this scenario, all IDOM is doing is attaching itself to the app. Then, it's up to you do actually run the app. For FastAPI, you can do that with uvicorn. Another way to think about this is that IDOM is just adding another route to app.
Beta Was this translation helpful? Give feedback.
All reactions
-
If you're still having trouble, book a slot during office hours: #312
Beta Was this translation helpful? Give feedback.