.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/fastapi_app.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_fastapi_app.py: FastAPI ------- Rendercanvas can do remote rendering as part of a web application. It implements its own little ASGI application, that can be mounted as part of a larger web application. This example demonstrates this with the FastAPI web framework. You can now run this like any AGI app, e.g. with uvicorn: uvicorn fastapi_app:app .. GENERATED FROM PYTHON SOURCE LINES 15-54 .. code-block:: Python from fastapi import FastAPI from fastapi.responses import HTMLResponse from rendercanvas.http import RenderCanvas, asgi from rendercanvas.utils.cube import setup_drawing_sync # FastAPI code app = FastAPI() @app.get("/", response_class=HTMLResponse) async def home(): return """ Test

Hello world

Head over to the rendercanvas client

""" # Prepare a canvas to render something canvas = RenderCanvas( title="The wgpu cube example on $backend", update_mode="continuous" ) draw_frame = setup_drawing_sync(canvas) canvas.request_draw(draw_frame) # Mount rendercanvas in the app app.mount("/rc", asgi) .. _sphx_glr_download_gallery_fastapi_app.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fastapi_app.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fastapi_app.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fastapi_app.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_