Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using idom from FastAPI #650

Unanswered
seeclearvision asked this question in Question
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 11 replies

Comment options

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.

You must be logged in to vote
11 replies
Comment options

Hi Mark/Ryan,
Would you happen to have a small app to kickstart an idom web app with a simple authentication?

Comment options

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.

Comment options

@seeclearvision just to follow up, have you managed to get things working?

Comment options

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.

Comment options

If you're still having trouble, book a slot during office hours: #312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /