Skip to content

Instantly share code, notes, and snippets.

@brumar
Last active April 21, 2021 14:45
Show Gist options
  • Select an option

  • Save brumar/ad2b6c151d439b97df875ad8f058965c to your computer and use it in GitHub Desktop.

Select an option

Save brumar/ad2b6c151d439b97df875ad8f058965c to your computer and use it in GitHub Desktop.
minimalist example to mount pywebio application on an existing fastapi application
"""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