Description
What is the problem or limitation you are having?
Positron currently provides backends for Django, Static web servers, and single-site web apps.
These options don't help if you have a FastAPI app that you want to wrap.
Describe the solution you'd like
Positron should provide a backend for bootstrapping a FastAPI project.
As with the Django and Static backends, running the bootstrap should produce a viable "FastAPI hello world". Ideally, that would be in a standalone server.py
file, alongside the app.py
that defines the Toga app, with the FastAPI server configuration referencing <appname>.server:app
as the entry point.
Describe alternatives you've considered
Do nothing, and let people define their own backends.
Additional context
See #3325 for a working example of an FastAPI configuration. The first comment contains the code for the working ASGI interface.
That code can't be used completely as is:
- The port and host don't need to be passed through the entire app. See the configuration of the Django and Static web servers for the right approach to app configuration.
- It will need to use
asgiref
, or another "pure python" ASGI server. uvicorn has a bunch of binary dependencies (including pydantic) that will prevent it from being used on mobile at present. - It would be desirable to find a better way to find the ephemeral port that is used by the app, rather than probing to create one. Some investigation on the server API will be required.
At the same time as implementing the FastAPI backend, it may be worth considering adding a "bare bones ASGI" implementation - that will be identical to the FastAPI backend, except that fastapi
won't be listed as a dependency, and the server.py
will be an essentially empty file that the user can put their own ASGI app into.