Falcon
Unburdening APIs for over 0.00 x 10-2 centuries.
Unburdening APIs for over 0.00 x 10-2 centuries.
# sample.py
import falcon
class QuoteResource:
def on_get(self, req, resp):
"""Handle GET requests."""
quote = {
'author': 'Grace Hopper',
'quote': (
"I've always been more interested in "
"the future than in the past."
),
}
resp.media = quote
app = falcon.App()
app.add_route('/quote', QuoteResource())
$ pip install falcon gunicorn
$ gunicorn sample:app
Falcon is a blazing fast, minimalist Python web API framework for building robust app backends and microservices. The framework works great with both asyncio (ASGI) and gevent/meinheld (WSGI).
LinkedIn, PayPal, Wargaming, GOVCERT.LU, and many others rely on Falcon to power mission-critical services. Falcon focuses on stability, correctness, and performance at scale.
The Falcon web framework encourages the REST architectural style. Resource classes implement HTTP method handlers that resolve requests and perform state transitions.
Falcon complements more general Python web frameworks by providing extra reliability, flexibility, and performance wherever you need it.
A number of Falcon add-ons, templates, and complementary packages are available for use in your projects. We've listed several of these on the Falcon wiki as a starting point, but you may also wish to search PyPI for additional resources.
Thanks to ASGI and WSGI, Falcon runs on a large variety of web servers and platforms. Falcon works great with CPython 3.5+. Or try PyPy for an extra speed boost!
We designed Falcon to support the demanding needs of large-scale microservices and responsive app backends. Falcon complements more general Python web frameworks by providing extra performance, reliability, and flexibility wherever you need it.
Reliable. We go to great lengths to avoid introducing breaking changes, and when we do, they are fully documented and only introduced (in the spirit of SemVer) with a major version increment. The code is rigorously tested with numerous inputs, and we require 100% coverage at all times. Falcon has no dependencies outside the standard library, helping minimize your app's attack surface while avoiding transitive bugs and breaking changes.
Debuggable. Falcon eschews magic. It's easy to tell which inputs lead to which outputs. Unhandled exceptions are never encapsulated or masked. Potentially surprising behaviors, such as automatic request body parsing, are well-documented and disabled by default. Finally, when it comes to the framework itself, we take care to keep logic paths simple and understandable. All this makes it easier to reason about the code and to debug edge cases in large-scale deployments.
Fast. Same hardware, more requests. Falcon turns around requests significantly faster than other popular Python frameworks like Django and Flask. For an extra speed boost, Falcon compiles itself with Cython when available, and also works well with PyPy. Considering a move to another programming language? Benchmark with Falcon+PyPy first!
Flexible. Falcon leaves a lot of decisions and implementation details to you, the API developer. This gives you a lot of freedom to customize and tune your implementation. It also helps you understand your apps at a deeper level, making them easier to tune, debug, and refactor over the long run. Falcon's minimalist design provides space for Python community members to independently innovate on Falcon add-ons and complementary packages.
Perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away.
Don't lower your expectations to meet your performance. Raise your level of performance to meet your expectations. Expect the best of yourself, and then do what is necessary to make it a reality.
To give you a feel for Falcon's performance, we've included the results of running a simple benchmark across several popular Python web frameworks.
Please note, however, that this benchmark is by no means comprehensive; it is only meant to provide a rough performance comparison between the given frameworks, and to demonstrate the baseline per-request overhead each framework incurs on an application.
As with any benchmark, you should take these numbers with a grain of salt. You should always run your own tests against your specific use case to discover what best suits your needs.
Scenario. The benchmark acts as a WSGI server and performs a GET request directly on each framework's PEP-3333 app. Requests are not sent over the network, since the performance of a given network or web server is not related to the performance of the WSGI frameworks themselves. Regardless, each app parses a route template with a single embedded parameter, reads a query parameter and a header from the request data, sets an x-header on the response, and finally returns a 10 KiB body, randomly generated.
Method. 50,000 iterations were executed per trial (100,000 for the PyPy tests), and the best time was recorded for each framework over 20 trials. The order in which the frameworks were tested was randomized for each trial. Also, garbage collection was enabled as it would be in a production environment, and a full collection was forcefully triggered before each trial. Finally, results were calculated using the Decimal class and rounded to the nearest whole number.
Platform. Benchmarks were executed by running the corresponding Docker images on a Google Compute Engine instance (Intel Skylake, 1vCPU, 2 GB RAM), running Ubuntu 18.04 with all system packages updated to their latest versions as of May 2019. The frameworks were tested on several different versions of Python.
Falcon was also benchmarked under CPython 3.7 with a more realistic scenario, in which the routing table had multiple entries, the query string contained percent-encoded characters, and several complex response headers were set in the response. Note that even when Falcon is doing more work, it still is able to outperform other frameworks, which are only doing the bare minimum to construct a response.
In order to be great, you just have to care. You have to care about your world, community, and equality.
Falcon is an Apache-licensed community project, built and supported by stylish volunteers from around the world.
Check out the Falcon talks, podcasts, and blog posts wiki page to learn more about the project, and to add your own resources.
A number of Falcon add-ons, templates, and complementary packages are available for use in your projects. We've listed several of these on the Falcon wiki as a starting point, but you may also wish to search PyPI for additional resources.
The Falconry community on Gitter is a great place to ask questions and share your ideas. You can find us in falconry/user. We also have a falconry/dev room for discussing the design and development of the framework itself.
Per our Code of Conduct, we expect everyone who participates in community discussions to act professionally. Please lead by example in encouraging constructive discussions. Each individual in the community is responsible for creating a positive, constructive, and productive culture.
Kurt Griffiths (kgriffs on GH, Gitter, and Twitter) is the original creator and primary maintainer of the Falcon framework. Kurt is generously assisted by members of the core project team, including John Vrbanac (jmvrbanac on GH and Gitter, and jvrbanac on Twitter), Vytautas Liuolia (vytas7 on GH and Gitter), and Nick Zaccardi (nZac on GH and Gitter).
We are all inventors, each sailing out on a voyage of discovery, guided each by a private chart, of which there is no duplicate. The world is all gates, all opportunities.
Falcon is an Apache-licensed community project, and is free to use. However, the large amount of time and effort needed to maintain the project and develop new features is not sustainable without the generous financial support of community members like you.
Please consider helping us secure the future of the Falcon framework with a one-time or recurring donation.
Your donation comes with some great perks, such as having your name listed in the BACKERS.md file, having your logo displayed on this website and in the docs, awesome T-shirts and glow-in-the-dark buttons, plus access to prioritized support from Falcon's core maintainers.
Project donations help subsidize the cost for Falcon's core maintainers team to maintain ecosystem projects and to engage with the community at PyCon and other venues.