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.
pip install falconVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a simple WSGI Falcon application. It defines a resource with an `on_get` method to handle GET requests to the `/quote` endpoint, returning a JSON response. The `falcon.App()` instance is then created and the resource is attached to a route. To serve this application, a WSGI server like Gunicorn is typically used. For ASGI applications, `falcon.asgi.App` and `async` responder methods would be used.
Upgrade your Python environment to 3.9+ and carefully review the Falcon 4.0 changelog for specific removals and breaking changes. Pay attention to deprecation warnings when upgrading from 3.x to 4.x.
Review your application's media type handling, especially if you rely on `req.client_prefers` or custom media handlers. Ensure your media types and their parameters are parsed as expected.
Ensure that your resource classes are thread-safe. Avoid storing mutable per-request state directly as instance attributes on the resource. Instead, use `req` and `resp` objects for per-request data, or ensure proper synchronization if shared state is intentionally modified.
Always use `req.get_media()` or `req.media` (for common types) or `req.stream` to read the request body in your responders. For example, `data = req.get_media()` to parse JSON or form data.
Implement custom error handlers using `app.add_error_handler()` for specific exception types you wish to handle differently, or for a general `Exception` to override the default 500 behavior.
Ensure Falcon is installed using `pip install falcon`. If a script is named `falcon.py`, rename it to avoid conflict. If using virtual environments, ensure the correct environment is activated.
Rename your Python file from `falcon.py` to something else (e.g., `app.py` or `main.py`) to prevent it from shadowing the installed `falcon` module.
Decode the bytes read from the request stream into a string before passing it to `json.loads()`. Alternatively, for common media types, use `req.media` or `req.get_media()` which handles decoding automatically.
Modify the URI templates to be unique and unambiguous. This often involves adjusting base paths or parameter definitions to ensure no two routes can match the same incoming URL.
Upgrade your Falcon installation to a version compatible with your Python interpreter, or downgrade your Python version to one supported by the older Falcon release. Falcon 4.0 and later require Python 3.9+.
No dependency data recorded yet.