Falcon Web Framework
Falcon is a minimalist, high-performance Python web API framework for building REST APIs and microservices. It provides a clean design that embraces HTTP and the REST architectural style, with a strong focus on reliability, correctness, and speed. The current version, 4.2.0, primarily contains typing enhancements and performance optimizations, including support for free-threaded CPython 3.14. Falcon supports both synchronous (WSGI) and asynchronous (ASGI) applications and typically follows a stable release cadence with regular updates.
Warnings
- breaking Falcon 4.0 dropped support for Python 3.5-3.7. Applications must use Python 3.8 or newer (Falcon 4.2.0 requires Python 3.9+). It also removed many functions, classes, and compatibility shims previously deprecated in the 3.x series.
- breaking Falcon 4.0 changed the behavior of media type parsing, specifically regarding the vendored `python-mimeparse` library and `req.client_prefers`. It also changed how media types with different values for the same parameters are considered.
- gotcha A single instance of each resource class is shared among all requests processed by a given worker. This means that any instance variables on your resource classes are shared across concurrent requests.
- gotcha Falcon does not automatically consume request bodies. For `application/json` or `application/x-www-form-urlencoded` content types, you must explicitly call `req.get_media()` or access `req.media` to parse the body. For other content types or direct stream access, use `req.stream`.
- deprecated As of Falcon 3.0, uncaught exceptions that do not inherit from `falcon.HTTPError` or `falcon.HTTPStatus` will no longer propagate to the application server. Instead, a default `HTTP 500` response will be returned, and details will be logged to `wsgi.errors`.
Install
-
pip install falcon
Imports
- App
import falcon app = falcon.App()
- ASGIApp
from falcon.asgi import App as ASGIApp app = ASGIApp()
- Request
from falcon import Request, Response
- Response
from falcon import Request, Response
- HTTP_200
import falcon resp.status = falcon.HTTP_200
Quickstart
import falcon
class QuoteResource:
def on_get(self, req: falcon.Request, resp: falcon.Response) -> None:
"""Handles GET requests."""
resp.status = falcon.HTTP_200
resp.media = {
'quote': "I've always been more interested in the future than in the past.",
'author': 'Grace Hopper',
}
# Instantiate a WSGI Falcon application
app = falcon.App()
# Create an instance of our resource
quotes = QuoteResource()
# Add a route to our application
app.add_route('/quote', quotes)
# To run this, save as `app.py` and then run:
# pip install gunicorn
# gunicorn app:app
# Then access via curl: curl http://127.0.0.1:8000/quote