Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active November 23, 2025 14:47
Show Gist options
  • Select an option

  • Save oprypin/052d58938a4cf2f95e8abfb82750773e to your computer and use it in GitHub Desktop.

Select an option

Save oprypin/052d58938a4cf2f95e8abfb82750773e to your computer and use it in GitHub Desktop.
Replace Quart with Flask in code - drop async features
import pathlib
import re
import subprocess
for fn in subprocess.check_output(["git", "ls-files"], encoding="utf-8").splitlines():
f = pathlib.Path(fn)
if not f.match("*.py"):
continue
content = f.read_text()
content = re.sub(r"\basync ", r"", content)
content = re.sub(r"\bawait ", r"", content)
content = re.sub(r"\bquart\b", r"flask", content)
content = re.sub(r"\bQuart\b", r"Flask", content)
content = re.sub(r"\b(Awaitable|Future)\[(.+?)\]", r"\2", content)
content = re.sub(r"\b(\w*)Async(\w+)\b", r"\1\2", content)
content = content.replace("async_", "")
content = re.sub(r"\basynccontextmanager\b", r"contextmanager", content)
content = re.sub(r"\basyncio\.ensure_future\b", r"", content)
content = re.sub(r"\baiosqlite\b", r"sqlite3", content)
content = re.sub(r"\bsqlite\+sqlite3\b", r"sqlite", content)
content = re.sub(r"\bsqlalchemy\.ext\.asyncio\.engine\b", r"sqlalchemy.engine", content)
content = re.sub(r"\b(\w+)\.run_sync\((.+?)(, .+?)?\)", r"\2(\1\3)", content)
f.write_text(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment