Add flask hello world and todo app - #89
Open
hoodmane wants to merge 2 commits into
Open
Conversation
ryanking13
reviewed
Aug 7, 2026
Contributor
There was a problem hiding this comment.
Why twenty 😅 ? The last number was 17.
| @@ -0,0 +1,26 @@ | |||
| import wsgi | |||
Contributor
There was a problem hiding this comment.
I think this should be workers.wsgi. We don't expose this top-level
| "start": "uv run pywrangler dev" | ||
| }, | ||
| "devDependencies": { | ||
| "wrangler": "^4.46.0" |
Contributor
There was a problem hiding this comment.
Let's use newer versions since we bumped the minimal wrangler version in workers-py. I updated all the examples recently #67.
Comment on lines
+10
to
+15
| # Local workers-runtime-sdk checkout (provides wsgi.py), built from source. | ||
| # pywrangler resolves the worker env from [project.dependencies] via | ||
| # `uv pip compile`, which ignores [tool.uv.sources] — so the local path must | ||
| # live directly in this string. Building a directory source requires the | ||
| # `[tool.pywrangler] allow-build` override below (turns off `--no-build`). | ||
| "workers-runtime-sdk @ file:///home/hood/Documents/programming/workers-py/packages/runtime-sdk", |
| readme = "README.md" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "webtypy>=0.1.7", |
Contributor
There was a problem hiding this comment.
We don't need webtypy here.
Comment on lines
+23
to
+31
| # Use the local workers-py (pywrangler) checkout so the `allow-build` override is | ||
| # available. This only affects the host dev tool, not the worker. | ||
| [tool.uv.sources] | ||
| workers-py = { path = "../../workers-py/packages/cli", editable = true } | ||
|
|
||
| [tool.pywrangler] | ||
| # Allow building sdists / local directory sources (drops `uv`'s `--no-build`), | ||
| # so the local workers-runtime-sdk directory above builds during sync. | ||
| allow-build = true |
Comment on lines
+5
to
+9
| "compatibility_date": "2025-11-02", | ||
| "compatibility_flags": [ | ||
| "python_workers", | ||
| "python_process_pth_files" | ||
| ], |
Contributor
There was a problem hiding this comment.
Maybe let's use newer compat dates
Comment on lines
+3
to
+16
| The D1 binding is a JavaScript object whose methods return promises. Flask is a | ||
| WSGI framework, so its view functions are plain synchronous Python and cannot | ||
| `await`. We bridge the two with `pyodide.ffi.run_sync`, which suspends the | ||
| Python stack until a JS promise settles, using JSPI (JavaScript Promise | ||
| Integration) stack switching. | ||
|
|
||
| `run_sync` only works while a JSPI suspender is on the stack. `workers.wsgi.fetch` | ||
| invokes the WSGI app from inside the Worker's async `fetch` handler, so that | ||
| condition holds for every request routed through `src/entry.py`. | ||
|
|
||
| The Workers SDK already converts D1's JS return values into Python objects: | ||
| `.all()` yields a mapping whose `results` key is a `list` of dict-like rows, and | ||
| `.first()` yields a dict-like row or `None`. No explicit `to_py()` is needed; | ||
| this module just normalizes them to plain `dict`s. |
Contributor
There was a problem hiding this comment.
This looks a bit verbose.
| this module just normalizes them to plain `dict`s. | ||
| """ | ||
|
|
||
| from pyodide.ffi import run_sync |
Contributor
There was a problem hiding this comment.
Can we use run_until_complete or asyncio.run instead? I think that would be more familiar to the users than using run_sync.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two flask examples: A hello world example and a todo-notes app.