Skip to content

Add a FastAPI and PyScript Positron bootstrap.#4156

Draft
freakboy3742 wants to merge 16 commits intobeeware:mainfrom
freakboy3742:fastapi
Draft

Add a FastAPI and PyScript Positron bootstrap.#4156
freakboy3742 wants to merge 16 commits intobeeware:mainfrom
freakboy3742:fastapi

Conversation

@freakboy3742
Copy link
Member

@freakboy3742 freakboy3742 commented Feb 2, 2026

  • Adds a FastAPI option for Positron.
  • Adds a question to the static web server asking for existing web content to copy into the app.
  • Adds a PyScript option for Positron. This is a hybrid of the FastAPI backend and the Static backend; details below
  • Does a refactor of the existing backends so that backends can share templating, "static content" capabilities, and to share the "can't deploy to web" option

The PyScript backend is a FastAPI backend that has the "copy static content" function of the Static backend. FastAPI is used so that a web socket can be exposed; a draft of the coincident websocket FFI handler is included, but it won't work at present because the supporting code isn't present.

The "copy existing static web content" question will generate dummy content by default; it has placeholder support for "clone content from a live web server", but doesn't actually implement that.

Fixes #3327.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Testing guide

For anyone wanting to test this - here's a step by step guide.

Create a positron-test directory:

mkdir positron-test
cd positron-test

Create and activate a Python3 virtual environment. If you're on Linux, this will need to be the system default python3 interpreter:

python3 -m venv venv
source ./venv/bin/activate

Clone the Toga repo, and checkout the code for this PR. I'm using the gh tool here; if you want to do it manually, you need the fastapi branch on my (@freakboy3742) fork of Toga:

git clone https://github.com/beeware/toga.git
cd toga
gh pr checkout 4156
cd ..

Install the checked-out version of Toga. If you're on macOS, use:

pip install -e ./toga/core -e ./toga/travertino -e ./toga/cocoa -e ./toga/positron

If you're on Linux, replace ./toga/cocoa with ./toga/gtk. On Window, use ./toga/winforms.

Create a new Briefcase project:

briefcase new

Answer all the wizard questions with whatever answers you want. One of the last questions asks about your preferred GUI framework; select "Toga Positron (FastAPI server)" or "Toga Positron (PyScript app)" to test out the new options.

When you run the PyScript test, it will ask you for the location of existing web content - this should be a directory path relative to where you're running Briefcase. If you just press enter, you'll get a dummy PyScript app that is enough to show that PyScript runs.

Then run the app. If you've accepted the default "Hello World" app name, this will be:

cd helloworld
briefcase dev

If you chose any other name, the briefcase new command should have shown you the commands to run.

@freakboy3742
Copy link
Member Author

In the current state, this can't deploy to iOS or Android; this is because Pydantic >= 2.0 is a hard requirement as of FastAPI 0.126.0; but even if you downgrade, uvicorn seems to use multiprocessing internally. I'm currently investigating options for this.

@freakboy3742
Copy link
Member Author

iOS and Android support has now been added. This requires pinning FastAPI to 0.125.0, as this is the last version that supports the use of Pydantic < 2. Pydantic 2 requires Pydantic-core, which is a Rust component; until we have a compiled version of that wheel available for iOS and Android, we can't upgrade.

It also requires a small shim for iOS to work around multiprocessing not being present (see python/cpython#134634).

@freakboy3742 freakboy3742 modified the milestone: 2026Q1 Feb 4, 2026
Co-authored-by: Russell Martin <russell@rjm.li>
@freakboy3742 freakboy3742 changed the title Add a FastAPI Positron bootstrap. Add a FastAPI and PyScript Positron bootstrap. Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a FastAPI backend to Toga Positron

2 participants