Registry / web-framework / falcon

falcon

JSON →
library4.3.1pypypi✓ verified 27d ago

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 falcon
INSTALL
IMPORT
SIG · FALCON
F
falcon
web-frameworkpythonv4.3.1
Install
1.8s avg
Import
435ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.464s · 21.6MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.406s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

App
✓ import falcon app = falcon.App()
✗ from falcon import App
While `from falcon import App` works, the idiomatic way for WSGI apps is `import falcon; app = falcon.App()` as `falcon` is the primary module. For ASGI apps, use `from falcon.asgi import App as ASGIApp`.
ASGIApp
✓ from falcon.asgi import App as ASGIApp app = ASGIApp()
For building asynchronous (ASGI) applications, import `App` specifically from `falcon.asgi` and alias it to avoid collision with the WSGI `App`.
Request
✓ from falcon import Request, Response
Commonly imported for type hinting in responder methods (e.g., `def on_get(self, req: Request, resp: Response):`).
Response
✓ from falcon import Request, Response
Commonly imported for type hinting in responder methods (e.g., `def on_get(self, req: Request, resp: Response):`).
HTTP_200
✓ import falcon resp.status = falcon.HTTP_200
HTTP status codes are exposed directly on the `falcon` module (e.g., `falcon.HTTP_200`, `falcon.HTTP_201`).

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.

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
Debug
Known issues
breakingFalcon 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.
fix
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.
affects: 4.0.0 and later
breakingFalcon 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.
fix
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.
affects: 4.0.0 and later
gotchaA 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.
fix
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.
affects: All versions
gotchaFalcon 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`.
fix
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.
affects: All versions
deprecatedAs 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`.
fix
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.
affects: 3.0.0 and later
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'falcon'
The 'falcon' package is not installed in the Python environment being used, or the Python interpreter cannot find it. This can also happen if a user's script is named `falcon.py`, shadowing the actual library.
fix
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.
AttributeError: 'module' object has no attribute 'API'
This error typically occurs when a user's Python file is named `falcon.py`, causing Python to import the user's file instead of the Falcon framework, which then lacks the `API` attribute.
fix
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.
TypeError: the JSON object must be str, not 'bytes'
When parsing a request body as JSON, `json.loads()` expects a string, but the `req.stream.read()` method (or `req.bounded_stream.read()`) returns bytes in Python 3.
fix
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.
ValueError: The URI template for this route conflicts with another route's template.
Two or more routes defined in the Falcon application have overlapping or identical URI templates, leading to ambiguity in how requests should be dispatched.
fix
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.
AttributeError: module 'falcon' has no attribute '__version__'
This error can occur when trying to install or run older versions of Falcon (e.g., 3.1.3) with newer Python versions (e.g., Python 3.13), where there might be a change in how `setuptools` or Python itself expects to find module metadata.
fix
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+.
Upgrade
Version history
4.3.1latest on PyPI · released Jun 16, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources