Python Frameworks: Full-Stack vs. Micro Framework
In part one of this series, we discussed the many different Python frameworks. Building on that, let's categorize them into full vs. micro-stack and analyze some of the top frameworks in each category.
Join the DZone community and get the full member experience.Join For Free
As we discussed in Part one of this two-part article series, there are many Python frameworks. Python.org breaks them down into three formats: full-stack, less than full-stack, and micro-stack. Today we are going to make it simple and separate them into full-stack and micro-stack. You’ll get an overview of some of the top frameworks in each category, the features that make them unique, and the reasons you should put them to work in your next application. First, let’s examine full-stack followed by micro-stack.
Full-stack frameworks do the heavy lifting of creating Python applications. Unlike the misty dawn of computer languages a few decades ago, today developers can tap the power of frameworks to provide them with libraries, templating engines, and database management. Here are some of the most popular full-stack frameworks:
Django is a high-level framework that makes it simple to create Web applications rapidly and with minimal code. It stresses pragmatic design and high performance. Django sticks closely to the don’t repeat yourself (DRY) principle and emphasizes automation.
Django has an approach that is sometimes called "batteries included" which means it has everything developers need to dive in and begin building right away. It has the components for routing, forms, templating, database administration, authentication, and more. Companies using Django include Pinterest, Instagram, and SportUp.
The philosophy behind TurboGears is to mash together some of the best components available. Rather than reinventing the wheel, it uses SQLAlchemy, Repose, Genshi, and Tosca Widget to build applications. With these powerful components, you can create database-driven applications very quickly. TurboGears includes robust templates, Ajax for the server and browser, and a powerful object-relational mapper (ORM). TurboGears was the framework of choice for sites like SourceForge, Bisque, and ShowMeDo.
With web2py, all development, testing, and database administration can be handled through the Web interface, although it is optional. Web2py has no configuration files, and no installation is necessary. There is a built-in ticketing system, caching system, and internalization engine.
Web2py works with multiple databases including MySQL, Oracle, and SQLite. You get libraries that handle JSON, CSV, RSS, AJAX, HTML/XML, and more. There is a strong concentration on backward compatibility, and web2py can handle the uploading and downloading of huge files. Sites using web2py include PikHotel, Braga TV, Formatics, and Tech Fuel.
Zope2 is one of the "old men" of the Python Web framework world. The original, Zope 1, came out in 1999. Zope2 has a split personality: it is a Web framework and an application server. The next iteration of the framework, Zope 3, can function as a standalone framework, and has many related libraries, also found in recent versions of Zope 2. Every version of Zope features ZODB, a Python object database. Companies using Zope2 include Panda Express, The Drug Company, and Technologijos.
Grok is based on Zope Toolkit. An open-source framework, it was formed in 2006 by several Zope programmers. It has technologies such as grokcore.component and Martian that are also used by other projects in the Zope family. The philosophy behind Grok is to speed up application development while making the Zope technology base easier to use for new developers. Instead of using an explicit XML language, Grok has opted for a convention-over-configuration approach. Grok has a similar user interface to other full-stack frameworks such as TurboGears and Pylons.
Micro-frameworks are small, easy to understand, and easy to use. They are terse and have simple documentation. URL routing is often RESTful. Micro-frameworks use WSGI and work through HTTP request/response. They are a good choice for small applications, or as part of a larger project. Here are five of the top Python micro-frameworks:
RESTful request dispatching
Strong community support
Companies using Flask include Papyrus Research, Punchfork, and Nuxeo.
Bottle is a simple Python micro-framework intended for small applications. It has request dispatching with URL support, a built-in HTTP server, key/value databases and templates, and can easily adapt to many third-party template engines. It comes in a single file and, other than the standard library that comes with Python, it has no dependencies. Its features include the following:
Templating engine Jinja2
Highly portable on many platforms
Low resource and disk space use
Easy to use
Applications written using Bottle include Wikitests.
CherryPy was created to make it easy to develop Web applications quickly by wrapping the HTTP protocol. It can function as a Web server on its own, or it can be launched through any environment compatible with WSGI. It does not handle templating or access to the backend. It can be extended with filters used in request/response processing.
Built-in tools for encoding, authorization, sessions, and caching
A system for developers to configure deployments
A full test suite as part of its core
Integrated profiling, coverage, and support for testing
Runs on multiple platforms including Android
Despite these advantages, some programmers feel the documentation needs improvement, and the framework could be easier to use. Websites using CherryPy include Netflix, Urbanility, and Indigo.
Bobo is a very lightweight framework created to develop Web applications that adhere to WSGI. From the beginning, the philosophy behind the development of the framework was that it should be easy to use and fun. Two main features are the ability to map URLs to objects and to call objects to get HTTP response.
As a micro framework, it was built to be lean and mean. It does not have a database integration layer, a templating engine or similar features provided by larger frameworks. Bobo’s strengths include low coupling and easy configuration. Bobo essentially has one task: to send a request to a Python object, gather some data, and send a response. There is no integration with the database at any time.
Web.py is a very simple, clean Web framework and library that was developed to create Python web applications. Other frameworks have more complexity while the thinking behind web.py is that it is better to keep things simple. Although it is a young framework in the early stages of development, it can create powerful applications rapidly.
Web.py was developed by Aaron Swartz in 2006, and he continues to guide and support web.py among other initiatives. It was initially used by Reddit when Aaron Swartz worked there. Web.py also powers Yandex, the largest Russian search engine, and local.ch, and telephone directory in Switzerland.
Web.py’s advantages include the following:
Is easy to use.
Can separate requests from POST and GET, useful for situations where your application depends on the request, for example, a REST API.
Is small and fast.
One of its disadvantages is its documentation, which can be improved.
Evolution of Python Frameworks
Most of these frameworks are designed to work with technology on the server. However, as Web frameworks evolve, some are starting to use Ajax code that is better suited for handling programming on the client side. In fact, we are beginning to see the emergence of complete applications operating in the browser. The benefit of these frameworks is that developers can concentrate on building the application itself while the framework takes on the tasks of infrastructure, communications, and other chores. The framework will interpret requests, create responses, and store data on a persistent basis.
Full Stack vs. Micro
We have made a distinction between full-stack frameworks and micro frameworks. The separation between the two is that full-stack frameworks have all of the tools you need to create an application from the user interface all the way back to the database. In contrast, micro-frameworks are better suited to small applications. However, many developers report they feel restricted by full-stack frameworks and prefer the flexibility of piecing together several micro-stack frameworks.
The key then is to examine each of these frameworks and determine which fits the goal of your project as well as the working style of the programmers involved. First consider a full-stack solution, because all of the components you need are right in the framework environment itself. If you have a smaller application, however, it may be better to concentrate on a micro-stack framework. These smaller frameworks are perfect for anything that does not need much code. Simple applications and small programs do not need the infrastructure of a great, full-stack development environment.
End of the Two-Part Series
This is the end of the second article in our two-part series on Python full-stack and micro-stack frameworks. Beyond the practical applications, each framework has its personality. Whether the framework has excellent documentation or not, the look and feel of the framework itself and other factors all come into play when deciding if you can work with this program through an entire project. That is a decision only you can make. Take your time to make a wise one.
Originally written by Tom Myers
Published at DZone with permission of , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.