Falcon is a web application framework dedicated to building web API servers. If other frameworks are popular cars packed with rich features such as template engines and O / R mappers, Falcon is a F1 machine-like frame that focuses and refines only the features needed for a Web API server. It is a work.
Notable is its simple design and overwhelming speed. The following is the benchmark posted on the official page (as of November 26, 2015, comparison result with PyPy 2.5.1).
It runs at 27 times faster than Flask and 1.5 to 2 times faster than Bottle, which is said to be a simple framework.
It's also very easy to implement. The following is an example implementation of a server that returns a simple JSON response.
If you execute it with python
, the server will start up on port 8000
, and when you access it, a JSON response will be returned.
example.py
import json
import falcon
class HelloResource(object):
def on_get(self, req, resp):
msg = {
"message": "Welcome to the Falcon"
}
resp.body = json.dumps(msg)
app = falcon.API()
app.add_route("/", HelloResource())
if __name__ == "__main__":
from wsgiref import simple_server
httpd = simple_server.make_server("127.0.0.1", 8000, app)
httpd.serve_forever()
and ʻon_post
.There is another feature that allows you to implement a so-called Filter called Hook, but that's the basics.
Since the Falcon application is a WSGI application, it can run on a WSGI server. In the above, the Python built-in simple_server
is used, but it can also be run with gunicorn or waitress (officially recommends gunicorn
, but I think that Windows people can not run it, so use waitress etc. I think it's good).
I think that it is suitable for the following situations.
We hope that you will try it out and experience its speed and ease of use.