Bottle doesnt need as much documentation as other frameworks_ but the docs are by no resources skimpy. All of the searching stuff fits on a one albeit long web page. Beyond that_ youll find full documentation for each API_ specimens for deploying on different infraconstructions_ an exposition of the built-in templating speech_ and a slew of ordinary recipes.
One effect of Bottles minimalism is that some items simply arent there. Form validation_ including components like CSRF cross-site request falsification shelter_ isnt included. If you want to build a web application that supports a high grade of user interaction_ youll need to add that support yourself.
Another effect with Bottle is that outgrowth has stalled; the last point release_ 0.12_ arrived in 2013. That said_ Bottle continues to be maintained_ and its outgrowth releases stay usable for origination. The developers intend to liberate new versions that shed support for legacy editions of Python.
<_aside> CherryPy CherryPy has been almost in one form or another for almost 20 years_ but hasnt lost the minimalism and beauty that illustrious it from the set.
The goal behind CherryPy_ aside from containing only the bare bits needed to obey web pages_ is to feel_ as far as practicable_ not like a “web framework” but like any other kind of Python application. Sites like Hulu and Netflix have used CherryPy in origination owing the framework prepares a greatly unobtrusive base to build on. CherryPy uses pooled threads below the hood_ the better to support multithreaded obeyr adapters.
CherryPy lets you keep your web application aloof from the core logic. To map your applications offices to URLs or ways obeyd by CherryPy_ you form a class where the namespaces of the objects map straightly to the URLs you want to obey. For entreaty_ the root of the website is granted by a office named “index.” Parameters passed to those offices are used to feel variables granted by GET or POST methods.
The bits that CherryPy includes are meant to work as low-level edifice blocks. Session identifiers and cookie handling are included_ but HTML templating is not. Like Bottle_ CherryPy offers a way to map ways to directories on-disk for static file serving.
CherryPy will frequently delay to an existing third-party library to support a component rather than prepare it indigenously. WebSocket applications_ for entreaty_ arent supported by CherryPy straightly_ but through the
The documentation for CherryPy includes a near tutorial walk-through of the different aspects of the program. It wont take you through a complete end-to-end application_ unlike some other framework tutorials_ but its quiet advantageous. The docs come with near notes on deployment in potential hosts_ reverse proxying via Apache and Nginx_ and many other scenarios.
If youre edifice REST-based APIs and nothing else_
Falcon was made just for you. Lean and fast_ with almost no dependencies over the measure library_ Falcon prepares seething you need for REST APIs and nothing more. Falcon 2.0_ released in 2019_ does away with Python 2.x support and requires at smallest Python 3.5.
A big part of why Falcon earns the “light and thin” label has pliant to do with the number of lines of code in the framework. Its owing Falcon imposes almost no construction of its own on applications. All a Falcon application has to do is show which offices map to which API endpoints. Returning JSON from an endpoint involves pliant more than setting up a way and recuring the data via the
json.dumps<_code> office from Pythons measure library. Support for async hasnt yet landed in Falcon_ but
work is below way to make that happen in Falcon 3.0.
Falcon also employs sane out-of-the-box lapses_ so pliant tinkering is needed for setup. For specimen_ 404s are liftd by lapse for any way thats not explicitly declared. If you want to recur faults to the client_ you can lift one of a number of stock qualifications bundled with the framework such as
HTTPBadRequest<_code> or use a general
falcon.HTTPError<_code> qualification. If you need preprocessing or postprocessing for a way_ Falcon prepares hooks for those as well.
Falcons centre on APIs resources theres pliant here for edifice web apps with assemblageal HTML user interfaces. Dont anticipate much in the way of form processing offices and CSRF shelter tools_ for entreaty. That said_ Falcon prepares graceful options to prolong its officeality_ so more sophisticated items can be built. Aside from the above-mentioned hooking mechanism_ youll find an interface for creating
middleware that can be used to wrap all of Falcons APIs.
The documentation for Falcon is thin compared to other frameworks_ but only owing theres less to cover. The user lead includes a regular step-by-step walk-through of all major components_ along with a fast-set section that lets you view specimen code with or without explanation.
FastAPIs name is a good summation of what it does. Its built to form API endpoints fastly_ and it runs fast too.
FastAPI makes use of the
Starlette project for its high-despatch networking core_ but you dont need to know almost Starlettes internals to use FastAPI. You mark endpoints in much the same mode as a Flask or Bottle app—use decorators to show which offices feel which ways—and then recur dictionaries that are translated automatically into JSON.
You can easily override how things are recured. For entreaty_ if you want to recur HTML_XML from some endpoints_ you can do that by simply recuring a manner
Response<_code> object. If you want to add manner middleware_ you can pop in anything that follows the ASGI measure.
FastAPI makes use of Pythons type hinting to prepare constraints on the kinds of data that ways welcome. For entreaty_ if you have a way with the type
Optional[int]<_code>_ FastAPI will repel any submissions except integers. You dont have to add data validation code to your endpoints; you can just use type hints and let FastAPI do the work.
Naturally_ some things are left out. Theres no indigenous HTML template engine_ for entreaty_ but theres no shortage of third-party solutions to fill that gap. Same with database connectivity_ but the documentation contains details almost how to coax true ORMs e.g. Peewee to work with FastAPIs async behaviors.
Many discussions almost Python web frameworks initiate with
Flask_ and for good reason. Flask is a well established_ well belowstood framework that is easy to use and perfectly firm. Its next to impracticable to go unfit using Flask for a lightweight web project or a basic REST API_ but youll face weighty lifting if you try to build anything bigr.
Flasks mediate accost is its low barrier to entrance. A basic “hello globe” app can be set up in
fewer than 10 lines of Python. Flask includes a widely used HTML templating method_ Jinja2_ to make rendering text easy_ but Jinja2 can be swapped out for any number of other template engines such as Mustache or you can roll your own.
In the name of artlessness_ Flask omits niceties such as a data layer or ORM_ and offers no provisions for the likes of form validation. However_ Flask can be swelled through
extensions_ of which there are dozens_ covering many ordinary use cases such as caching_ form handling and validation_ and database connectivity. This lean-by-lapse design allows you to set engineering a Flask application with the perfect minimum of officeality_ then layer in only the pieces you need when you need them.
Flasks documentation is warm and easy to read. The
fast-set document does an excellent job of getting you seted while also exleveling the significance of the lapse choices for a one Flask application_ and the API docs are replete with good specimens. Also excellent is the assembly of Flash snippets_ which are fast-and-dirty specimens of how to execute specific tasks_ such as how to recur an object if it exists or a 404 fault if it doesnt.
Flask hit its milestone 1.0 release in 2018_ with Python 2.6 and Python 3.3 being the minimum supported versions_ and with many of its behaviors finally set in stone. Flask doesnt explicitly support Pythons async syntax_ but an API-compatible deviation of Flask named
Quart has been spun off to satiate that claim.