Skip to content

Add a FastAPI backend to Toga Positron #3327

Open
@freakboy3742

Description

@freakboy3742

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:

  1. 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.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.good first issueIs this your first time contributing? This could be a good place to start!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions