Project description

Perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away.

*- Antoine de Saint-Exupéry*

`Falcon <http://falconframework.org/index.html>`__ is a reliable,high-performance Python web framework for buildinglarge-scale app backends and microservices. It encourages the RESTarchitectural style, and tries to do as little as possible whileremaining highly effective.

Falcon apps work with any WSGI server, and run great underCPython 2.6-2.7, PyPy 2.7, Jython 2.7, and CPython 3.3+.

(Note: Support for CPython 2.6 and Jython 2.7 is deprecated and will beremoved in Falcon 2.0.)

We designed Falcon to support the demanding needs of large-scalemicroservices and responsive app backends. Falcon complements moregeneral Python web frameworks by providing bare-metal performance,reliability, and flexibility wherever you need it.

**Fast.** Same hardware, more requests. Falcon turns aroundrequests several times faster than most other Python frameworks. Foran extra speed boost, Falcon compiles itself with Cython whenavailable, and also works well with `PyPy <https://pypy.org>`__.Considering a move to another programming language? Benchmark withFalcon + PyPy first.

**Reliable.** We go to great lengths to avoid introducingbreaking changes, and when we do they are fully documented and onlyintroduced (in the spirit of`SemVer <http://semver.org/>`__) with a major versionincrement. The code is rigorously tested with numerous inputs and werequire 100% coverage at all times. Six and mimeparse are the onlythird-party dependencies.

**Flexible.** Falcon leaves a lot of decisions and implementationdetails to you, the API developer. This gives you a lot of freedom tocustomize and tune your implementation. Due to Falcon's minimalistdesign, Python community members are free to independently innovate on`Falcon add-ons and complementary packages <https://github.com/falconry/falcon/wiki>`__.

**Debuggable.** Falcon eschews magic. It's easy to tell which inputslead to which outputs. Unhandled exceptions are never encapsulated ormasked. Potentially surprising behaviors, such as automatic request bodyparsing, are well-documented and disabled by default. Finally, when itcomes to the framework itself, we take care to keep logic paths simpleand understandable. All this makes it easier to reason about the codeand to debug edge cases in large-scale deployments.

If you are using the Falcon framework for a community or commercialproject, please consider adding your information to our wiki under`Who's Using Falcon? <https://github.com/falconry/falcon/wiki/Who's-using-Falcon%3F>`_

Community---------

A number of Falcon add-ons, templates, and complementary packages areavailable for use in your projects. We've listed several of these on the`Falcon wiki <https://github.com/falconry/falcon/wiki>`_ as a startingpoint, but you may also wish to search PyPI for additional resources.

The Falconry community on Gitter is a great place to ask questions andshare your ideas. You can find us in `falconry/user<https://gitter.im/falconry/user>`_. We also have a`falconry/dev <https://gitter.im/falconry/dev>`_ room for discussingthe design and development of the framework itself.

Per our`Code of Conduct <https://github.com/falconry/falcon/blob/master/CODEOFCONDUCT.md>`_,we expect everyone who participates in community discussions to actprofessionally, and lead by example in encouraging constructivediscussions. Each individual in the community is responsible forcreating a positive, constructive, and productive culture.

Installation------------

PyPy^^^^

`PyPy <http://pypy.org/>`__ is the fastest way to run your Falcon app.However, note that only the PyPy 2.7 compatible release is currentlysupported.

A universal wheel is available on PyPI for the the Falcon framework.Installing it is as simple as:

.. code:: bash

$ pip install falcon

If `ujson <https://pypi.python.org/pypi/ujson>`__ is available, Falconwill use it to speed up media (de)serialization, error serialization,and query string parsing. Note that ``ujson`` can actually be sloweron PyPy than the standard ``json`` module due to ctypes overhead, andso we recommend only using ``ujson`` with CPython deployments:

.. code:: bash

$ pip install ujson

Installing the Falcon wheel is a great way to get up and runningquickly in a development environment, but for an extra speed boost whendeploying your application in production, Falcon can compile itself withCython.

The following commands tell pip to install Cython, and then to invokeFalcon's ``setup.py``, which will in turn detect the presence of Cythonand then compile (AKA cythonize) the Falcon framework with the system'sdefault C compiler.

.. code:: bash

$ pip install cython $ pip install --no-binary :all: falcon

If you want to verify that Cython is being invoked, simplypass `-v` to pip in order to echo the compilation commands:

.. code:: bash

$ pip install -v --no-binary :all: falcon

**Installing on OS X**

Xcode Command Line Tools are required to compile Cython. Install themwith this command:

You might also see warnings about unused functions. You can work aroundthese issues by setting additional Clang C compiler flags as follows:

.. code:: bash

$ export CFLAGS="-Qunused-arguments -Wno-unused-function"

Dependencies^^^^^^^^^^^^

Falcon depends on `six` and `python-mimeparse`. `python-mimeparse` is abetter-maintained fork of the similarly named `mimeparse` project.Normally the correct package will be selected by Falcon's ``setup.py``.However, if you are using an alternate strategy to manage dependencies,please take care to install the correct package in order to avoiderrors.

WSGI Server-----------

Falcon speaks WSGI, and so in order to serve a Falcon app, you willneed a WSGI server. Gunicorn and uWSGI are some of the more popularones out there, but anything that can load a WSGI app will do.

.. code:: bash

$ pip install [gunicorn|uwsgi]

Source Code-----------

Falcon `lives on GitHub <https://github.com/falconry/falcon>`_, making thecode easy to browse, download, fork, etc. Pull requests are always welcome! Also,please remember to star the project if it makes you happy. :)

Once you have cloned the repo or downloaded a tarball from GitHub, youcan install Falcon like this:

.. code:: bash

$ cd falcon $ pip install .

Or, if you want to edit the code, first fork the main repo, clone the forkto your desktop, and then run the following to install it using symboliclinking, so that when you change your code, the changes will be automagicallyavailable to your app without having to reinstall the package:

.. code:: bash

$ cd falcon $ pip install -e .

You can manually test changes to the Falcon framework by switching to thedirectory of the cloned repo and then running pytest:

.. code:: bash

$ cd falcon $ pip install -r requirements/tests $ pytest tests

Or, to run the default set of tests:

.. code:: bash

$ pip install tox && tox

See also the `tox.ini <https://github.com/falconry/falcon/blob/master/tox.ini>`_file for a full list of available environments.

Read the docs-------------

The docstrings in the Falcon code base are quite extensive, and werecommend keeping a REPL running while learning the framework so thatyou can query the various modules and classes as you have questions.

Online docs are available at: https://falcon.readthedocs.io

You can build the same docs locally as follows:

.. code:: bash

$ pip install tox && tox -e docs

Once the docs have been built, you can view them by opening the followingindex page in your browser. On OS X it's as simple as::

$ open docs/_build/html/index.html

Or on Linux:

$ xdg-open docs/_build/html/index.html

Getting started---------------

Here is a simple, contrived example showing how to create a Falcon-basedAPI.

if req.method in ('POST', 'PUT'): if 'application/json' not in req.content_type: raise falcon.HTTPUnsupportedMediaType( 'This API only supports requests encoded as JSON.', href='http://docs.examples.com/api/json')

class JSONTranslator(object): # NOTE: Starting with Falcon 1.3, you can simply # use req.media and resp.media for this instead.

def process_request(self, req, resp): # req.stream corresponds to the WSGI wsgi.input environ variable, # and allows you to read bytes from the request body. # # See also: PEP 3333 if req.content_length in (None, 0): # Nothing to do return

# An alternative way of doing DRY serialization would be to # create a custom class that inherits from falcon.Request. This # class could, for example, have an additional 'doc' property # that would serialize to JSON under the covers. # # NOTE: Starting with Falcon 1.3, you can simply # use resp.media for this instead. resp.context['result'] = result

# If a responder ever raised an instance of StorageError, pass control to # the given handler. app.add_error_handler(StorageError, StorageError.handle)

# Proxy some things to another service; this example shows how you might # send parts of an API off to a legacy system that hasn't been upgraded # yet, or perhaps is a single cluster that all data centers have to share. sink = SinkAdapter() app.add_sink(sink, r'/search/(?P<engine>ddg|y)\Z')

# Useful for debugging problems in your API; works with pdb.set_trace(). You # can also use Gunicorn to host your app. Gunicorn can be configured to # auto-restart workers when it detects a code change, and it also works # with pdb. if __name__ == '__main__': httpd = simple_server.make_server('127.0.0.1', 8000, app) httpd.serve_forever()

Contributing------------

Thanks for your interest in the project! We welcome pull requests fromdevelopers of all skill levels. To get started, simply fork the master branchon GitHub to your personal account and then clone the fork into yourdevelopment environment.

If you would like to contribute but don't already have something in mind,we invite you to take a look at the issues listed under our`next milestone <https://github.com/falconry/falcon/milestones>`_.If you see one you'd like to work on, please leave a quick comment so that we don'tend up with duplicated effort. Thanks in advance!

Please note that all contributors and maintainers of this project are subject to our `Code of Conduct <https://github.com/falconry/falcon/blob/master/CODEOFCONDUCT.md>`_.

Before submitting a pull request, please ensure you have added/updatedthe appropriate tests (and that all existing tests still pass with yourchanges), and that your coding style follows PEP 8 and doesn't causepyflakes to complain.

Commit messages should be formatted using `AngularJSconventions <http://goo.gl/QpbS7>`__.

- TODO(riker): Damage report!- NOTE(riker): Well, that's certainly good to know.- PERF(riker): Travel time to the nearest starbase?- APPSEC(riker): In all trust, there is the possibility for betrayal.

Kurt Griffiths (**kgriffs** on GH, Gitter, and Twitter) is the originalcreator of the Falcon framework, and currently co-maintains the projectalong with John Vrbanac (**jmvrbanac** on GH and Gitter, and**jvrbanac** on Twitter). Falcon is developed by a growing community ofstylish users and contributors just like you.

Please don't hesitate to reach out if you have any questions, or just need alittle help getting started. You can find us in`falconry/dev <https://gitter.im/falconry/dev>`_ on Gitter.

Licensed under the Apache License, Version 2.0 (the "License"); you maynot use any portion of the Falcon framework except in compliance withthe License. Contributors agree to license their work under the sameLicense. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.