Top Quart (async Flask) Extensions
Episode Deep Dive
Guest Background (Philip Jones)
Philip Jones is a seasoned software engineer based in London with a notable background in particle physics. Before moving into software, he worked on a deep-mine experiment in Canada. Now, he’s a driving force behind the Quart web framework and Hypercorn server, collaborating closely with the Flask (Pallets) team. He’s also held professional roles at companies innovating in diverse spaces, including medical cannabis in the UK.
What to Know if You’re New to Python
- Quart is built on top of the familiar Flask API, so if you understand Flask, you’ll quickly grasp Quart’s concepts.
- Asynchronous development (async/await) is a key difference, letting you handle multiple tasks more efficiently.
- Consider taking Python for Absolute Beginners or Async Techniques and Examples in Python from Talk Python Training if you’re new to Python or want a deeper dive into async.
- If you’d like to learn about building database-driven applications with Flask, check out Building Data-Driven Web Apps with Flask and SQLAlchemy.
- Basic Python data structures and knowledge of
pip install
will help you explore the libraries and extensions mentioned here.
Key Topics & Takeaways
Origins and Philosophy of Quart
- Quart evolved from the idea of bringing true async capabilities to Flask. Rather than modifying Flask directly, Philip re-implemented its API using
async
andawait
. - Ongoing collaboration with Flask’s maintainers aims to keep Quart and Flask closely in sync while pushing asynchronous features forward.
- Quote from Philip: “Over the years, David and I have worked to try and merge the two together… You can take your Flask code base and move to Quart just by adding async and await. That’s the dream.”
- Link: Quart Framework
- Quart evolved from the idea of bringing true async capabilities to Flask. Rather than modifying Flask directly, Philip re-implemented its API using
Hypercorn: The Async Server
- Philip created Hypercorn to serve Quart applications. It supports ASGI and WSGI, plus HTTP/2 and HTTP/3.
- Compared to other servers like Uvicorn or Gunicorn-with-UVicorn-workers, Hypercorn stands out for multi-protocol support (HTTP/1.1, HTTP/2, and HTTP/3) and the ability to run both sync and async apps in one place.
- This flexibility lets you fine-tune performance or take advantage of advanced features like push-based connections or multi-worker deployment.
Top Quart Extensions
- quart-cors: GitHub – Simplifies configuring CORS, a must if your frontend code or APIs need cross-origin requests.
- quart-auth: GitHub – Session-based user authentication, similar to Flask-Login, but fully async.
- quart-rate-limiter: GitHub – Implements rate limiting for routes to prevent abuse or brute-force attempts, returning proper HTTP 429 responses.
- quart-schema: GitHub – Validates incoming and outgoing data (JSON schemas, data classes, Pydantic, etc.) and can generate OpenAPI docs.
- quart-minify: GitHub – On-the-fly or cached minification of CSS and JS assets. Handy when you need quick optimization.
- quart-db: GitHub – Direct database connections (e.g., PostgreSQL, SQLite) for developers who prefer writing SQL without a full ORM.
quart-tasks: Native Background Tasks
- Link: Quart Tasks Documentation
- Allows you to schedule background tasks (e.g., sending reminder emails daily) without separate infrastructure like Celery or cron.
- Write an
async def
for tasks that do async I/O or adef
for truly blocking code, and Quart handles them in the event loop or a separate thread. - Especially beneficial for smaller apps or prototypes that don’t justify a separate distributed task queue.
Using Flask Extensions on Quart
- There is a compatibility approach with
quart_flask_patch
, letting some Flask extensions (e.g., Flask-Login) run under Quart with minimal changes. - Helps teams transition from Flask to Quart gradually, particularly if your code relies on popular Flask libraries.
- Not all Flask extensions will work perfectly—success depends on whether they rely on deeper Flask internals or do custom I/O.
- There is a compatibility approach with
Security Hardening & Headers
- Tools like secure simplify adding secure headers (e.g.,
X-Frame-Options
,Content-Security-Policy
) to your Quart app. - Properly configured same-site cookies (
Strict
orLax
) and cryptographic signing are essential for session security, especially if you manage logins. - For advanced usage, libraries like Greenback can help re-enter asyncio loops from sync code, though it’s a more specialized approach.
- Tools like secure simplify adding secure headers (e.g.,
WebSockets and Server-Sent Events (SSE)
- Quart natively supports WebSockets, letting you handle real-time, bidirectional communication easily via
async
routes. - For one-way push updates (like notifications or streaming events), Server-Sent Events are often simpler and require no extra library overhead.
- Many developers default to WebSockets for push, but SSE is often the perfect fit if you only need server-to-client streams.
- Quart natively supports WebSockets, letting you handle real-time, bidirectional communication easily via
Database Integration Options
- Use
quart-sqlalchemy
(similar to Flask-SQLAlchemy) if you prefer an ORM approach. - The built-in async capability pairs well with libraries like Beanie (for MongoDB) or any motor-based integration.
- For direct SQL,
quart-db
offers a simpler syntax to run raw queries and handle transactions.
- Use
Quotes & Stories
- On switching from Flask to Quart: “You can take your Flask code base and move to Quart just by adding async and await.”
- On advanced protocol support: Philip highlighted the excitement of HTTP/2 and HTTP/3 within Hypercorn, though he notes it’s still a niche feature for many applications.
Overall Takeaway
Quart opens doors to powerful async patterns without discarding the simplicity and familiarity of Flask. From background tasks to security headers, from rate limiting to schema validation, the ecosystem around Quart has grown into a robust set of tools for modern web development. Whether you’re migrating an existing Flask app or starting fresh with async features, Philip Jones’s work on Quart, Hypercorn, and these extensions demonstrates a clear path forward for Python web developers who need both flexibility and performance.
Links from the show
Quart Framework: quart.palletsprojects.com
Using Quart Extensions: quart.palletsprojects.com
Quart Tasks: quart-tasks.readthedocs.io
Quart Minify: github.com
Quart Db: github.com
Hypercorn: github.com
Quart-CORS: github.com
Quart-Auth: github.com
Quart-Rate: github.com
Quart-Schma: github.com
Flask-Socket: github.com
Quart-SqlAlchemy: github.com
Flask-Login: github.com
greenback: github.com
secure: github.com
msgspec: jcristharif.com
Server-Sent Events: pgjones.gitlab.io
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy