Convert Figma logo to code with AI

pallets logoquart

An async Python micro framework for building web applications.

2,887
158
2,887
38

Top Related Projects

10,027

The little ASGI framework that shines. 🌟

75,446

FastAPI framework, high performance, easy to learn, fast to code, ready for production

79,088

The Web framework for perfectionists with deadlines.

21,674

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

14,938

Asynchronous HTTP client/server framework for asyncio and Python

Quick Overview

Quart is an asynchronous Python web microframework that is compatible with the Flask API. It allows developers to write web applications using familiar Flask-like syntax while leveraging the power of asynchronous programming. Quart is designed to be a drop-in replacement for Flask, making it easy for Flask developers to transition to asynchronous development.

Pros

  • Asynchronous performance: Quart can handle a higher number of concurrent requests compared to Flask due to its asynchronous nature.
  • Flask compatibility: Existing Flask applications can be easily ported to Quart with minimal changes.
  • WebSocket support: Quart provides built-in support for WebSockets, enabling real-time communication.
  • ASGI compliance: Quart is compatible with ASGI servers, allowing for deployment on modern asynchronous server platforms.

Cons

  • Learning curve: Developers new to asynchronous programming may face a learning curve when working with Quart.
  • Limited ecosystem: While growing, Quart's ecosystem of extensions and plugins is not as extensive as Flask's.
  • Potential compatibility issues: Some Flask extensions may not work seamlessly with Quart without modifications.

Code Examples

  1. Basic Quart application:
from quart import Quart

app = Quart(__name__)

@app.route('/')
async def hello():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()
  1. Asynchronous route with database query:
from quart import Quart
import aiosqlite

app = Quart(__name__)

@app.route('/users/<int:user_id>')
async def get_user(user_id):
    async with aiosqlite.connect('database.db') as db:
        async with db.execute('SELECT * FROM users WHERE id = ?', (user_id,)) as cursor:
            user = await cursor.fetchone()
    return {'user': user}
  1. WebSocket example:
from quart import Quart, websocket

app = Quart(__name__)

@app.websocket('/ws')
async def ws():
    while True:
        data = await websocket.receive()
        await websocket.send(f"Echo: {data}")

Getting Started

To get started with Quart, follow these steps:

  1. Install Quart:

    pip install quart
    
  2. Create a new file named app.py with the following content:

    from quart import Quart, render_template
    
    app = Quart(__name__)
    
    @app.route('/')
    async def index():
        return await render_template('index.html')
    
    if __name__ == '__main__':
        app.run()
    
  3. Create a templates folder and add an index.html file with your desired content.

  4. Run the application:

    python app.py
    
  5. Open a web browser and navigate to http://localhost:5000 to see your Quart application in action.

Competitor Comparisons

10,027

The little ASGI framework that shines. 🌟

Pros of Starlette

  • Lightweight and fast, with excellent performance benchmarks
  • Built-in WebSocket support
  • More flexible routing system with path parameters and type conversion

Cons of Starlette

  • Less opinionated, requiring more setup for larger applications
  • Fewer built-in features compared to Quart's Flask-like ecosystem
  • Steeper learning curve for developers familiar with Flask-style frameworks

Code Comparison

Starlette:

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route

async def homepage(request):
    return JSONResponse({"message": "Hello, World!"})

app = Starlette(routes=[Route("/", homepage)])

Quart:

from quart import Quart, jsonify

app = Quart(__name__)

@app.route("/")
async def homepage():
    return jsonify({"message": "Hello, World!"})

Both Starlette and Quart are asynchronous Python web frameworks, but they have different design philosophies. Starlette focuses on being a lightweight ASGI toolkit, while Quart aims to be an asynchronous alternative to Flask with a similar API. The code comparison shows that Starlette requires more explicit setup, while Quart follows a more familiar Flask-like structure.

75,446

FastAPI framework, high performance, easy to learn, fast to code, ready for production

Pros of FastAPI

  • Built-in support for data validation and serialization using Pydantic models
  • Automatic API documentation generation with Swagger UI and ReDoc
  • High performance due to Starlette backend and async support

Cons of FastAPI

  • Steeper learning curve for developers new to type annotations and Pydantic
  • Less flexibility in request handling compared to Quart's ASGI-native approach

Code Comparison

FastAPI:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

Quart:

from quart import Quart

app = Quart(__name__)

@app.route("/")
async def root():
    return {"message": "Hello World"}

Both frameworks offer similar syntax for defining routes and handling requests. FastAPI leverages type hints for request/response validation, while Quart follows a Flask-like approach with ASGI support. FastAPI's automatic documentation generation and built-in data validation make it attractive for API development, while Quart's compatibility with Flask extensions and ASGI-native design provide flexibility for various web application scenarios.

79,088

The Web framework for perfectionists with deadlines.

Pros of Django

  • Comprehensive full-stack framework with built-in ORM, admin interface, and authentication
  • Large ecosystem with extensive third-party packages and plugins
  • Robust documentation and strong community support

Cons of Django

  • Steeper learning curve due to its monolithic nature
  • Less flexibility for customization compared to lightweight frameworks
  • Potentially slower performance for simple applications due to overhead

Code Comparison

Django:

from django.http import HttpResponse
from django.urls import path

def hello(request):
    return HttpResponse("Hello, World!")

urlpatterns = [
    path('hello/', hello),
]

Quart:

from quart import Quart

app = Quart(__name__)

@app.route('/hello')
async def hello():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

The code comparison shows that Quart uses async/await syntax and decorators for routing, while Django uses function-based views and a separate URL configuration. Quart's approach is more similar to Flask, offering a simpler and more lightweight setup for small applications or microservices. Django's structure is more suited for larger, complex projects with multiple components.

21,674

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

Pros of Tornado

  • Mature and battle-tested framework with a long history of production use
  • Built-in support for WebSockets and long polling
  • Non-blocking I/O and coroutines for high concurrency

Cons of Tornado

  • Less active development compared to more modern frameworks
  • Steeper learning curve, especially for developers new to asynchronous programming
  • Limited ecosystem of extensions and plugins

Code Comparison

Tornado:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, World!")

if __name__ == "__main__":
    application = tornado.web.Application([(r"/", MainHandler)])
    application.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Quart:

from quart import Quart

app = Quart(__name__)

@app.route("/")
async def hello():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()

Both frameworks provide asynchronous capabilities, but Quart offers a more Flask-like syntax, making it easier for developers familiar with Flask to transition to asynchronous programming. Tornado's code is more verbose but provides finer control over request handling.

14,938

Asynchronous HTTP client/server framework for asyncio and Python

Pros of aiohttp

  • More mature and widely adopted project with a larger ecosystem
  • Supports both client and server-side HTTP functionality
  • Offers lower-level control and flexibility for advanced use cases

Cons of aiohttp

  • Steeper learning curve, especially for developers new to asynchronous programming
  • Less intuitive API compared to Flask-like frameworks
  • Requires more boilerplate code for common web application tasks

Code Comparison

aiohttp example:

from aiohttp import web

async def hello(request):
    return web.Response(text="Hello, World!")

app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app)

Quart example:

from quart import Quart

app = Quart(__name__)

@app.route('/')
async def hello():
    return 'Hello, World!'

app.run()

Both aiohttp and Quart are asynchronous web frameworks for Python, but they cater to different use cases and developer preferences. aiohttp is more versatile and powerful, while Quart offers a familiar Flask-like experience with async capabilities. The choice between them depends on the specific project requirements and the developer's comfort with asynchronous programming concepts.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Quart

.. image:: https://raw.githubusercontent.com/pallets/quart/main/artwork/logo.png :alt: Quart logo

|Build Status| |docs| |pypi| |python| |license| |chat|

Quart is an async Python web microframework. Using Quart you can,

  • render and serve HTML templates,
  • write (RESTful) JSON APIs,
  • serve WebSockets,
  • stream request and response data,
  • do pretty much anything over the HTTP or WebSocket protocols.

Quickstart

Quart can be installed via pip <https://docs.python.org/3/installing/index.html>_,

.. code-block:: console

$ pip install quart

and requires Python 3.8.0 or higher (see python version support <https://quart.palletsprojects.com/en/latest/discussion/python_versions.html>_ for reasoning).

A minimal Quart example is,

.. code-block:: python

from quart import Quart, render_template, websocket

app = Quart(__name__)

@app.route("/")
async def hello():
    return await render_template("index.html")

@app.route("/api")
async def json():
    return {"hello": "world"}

@app.websocket("/ws")
async def ws():
    while True:
        await websocket.send("hello")
        await websocket.send_json({"hello": "world"})

if __name__ == "__main__":
    app.run()

if the above is in a file called app.py it can be run as,

.. code-block:: console

$ python app.py

To deploy this app in a production setting see the deployment <https://quart.palletsprojects.com/en/latest/tutorials/deployment.html>_ documentation.

Contributing

Quart is developed on GitHub <https://github.com/pallets/quart>. If you come across an issue, or have a feature request please open an issue <https://github.com/pallets/quart/issues>. If you want to contribute a fix or the feature-implementation please do (typo fixes welcome), by proposing a merge request <https://github.com/pallets/quart/pulls>_.

Testing ^^^^^^^

The best way to test Quart is with Tox <https://tox.readthedocs.io>_,

.. code-block:: console

$ pip install tox
$ tox

this will check the code style and run the tests.

Help

The Quart documentation <https://quart.palletsprojects.com>_ or cheatsheet <https://quart.palletsprojects.com/en/latest/reference/cheatsheet.html>_ are the best places to start, after that try searching stack overflow <https://stackoverflow.com/questions/tagged/quart>_ or ask for help on discord <https://discord.gg/pallets>. If you still can't find an answer please open an issue <https://github.com/pallets/quart/issues>.

Relationship with Flask

Quart is an asyncio reimplementation of the popular Flask <https://flask.palletsprojects.com>_ microframework API. This means that if you understand Flask you understand Quart.

Like Flask, Quart has an ecosystem of extensions for more specific needs. In addition a number of the Flask extensions work with Quart.

Migrating from Flask ^^^^^^^^^^^^^^^^^^^^

It should be possible to migrate to Quart from Flask by a find and replace of flask to quart and then adding async and await keywords. See the docs <https://quart.palletsprojects.com/en/latest/how_to_guides/flask_migration.html>_ for more help.

.. |Build Status| image:: https://github.com/pallets/quart/actions/workflows/tests.yaml/badge.svg :target: https://github.com/pallets/quart/commits/main

.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg :target: https://quart.palletsprojects.com

.. |pypi| image:: https://img.shields.io/pypi/v/quart.svg :target: https://pypi.python.org/pypi/Quart/

.. |python| image:: https://img.shields.io/pypi/pyversions/quart.svg :target: https://pypi.python.org/pypi/Quart/

.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg :target: https://github.com/pallets/quart/blob/main/LICENSE

.. |chat| image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg :target: https://discord.gg/pallets