Last active
April 21, 2021 14:45
-
-
Save brumar/ad2b6c151d439b97df875ad8f058965c to your computer and use it in GitHub Desktop.
minimalist example to mount pywebio application on an existing fastapi application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Install these requirements | |
| pip install git+https://github.com/wang0618/PyWebIO fastapi starlette uvicorn aiofiles websockets | |
| and run | |
| python main.py | |
| """ | |
| import uvicorn | |
| from fastapi import FastAPI | |
| from pywebio.platform.fastapi import asgi_app | |
| from pywebio.output import put_text | |
| app = FastAPI() | |
| app2 = asgi_app(lambda: put_text("hello from pywebio")) | |
| app.mount("/pywebio", app2) | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment