8 Open-Source Frameworks for Building APIs in Python Tyler Charboneau April 4, 2019 Python is a highly-capable language, primed to handle the rigors of API development. Popularized by major companies and smaller development teams, Python is applauded for its user-friendliness. However, Python owes much of that usability to various development platforms. We always appreciate when developer communities collaborate to build smarter tools, and luckily, a plethora of open-source frameworks have burst onto the scene and matured. Tailored to unique sets of project requirements, these web frameworks expedite API development. Below is our breakdown of eight powerful Python web frameworks to help you tackle your coding endeavors. 1. Flask The customizable framework that gives developers complete control from day one. Flask is a Python micro-framework based on Werkzeug’s WSGI toolkit and Jinja 2’s templating engine. Created by Armin Ronacher in 2010, Flask has been updated 27 times since its debut. It remains one of the fastest-growing Python frameworks to date. Users may join a community mailing list, tune into Flask’s IRC channel, or chip in contributions on GitHub. Pinterest, Netflix, and LinkedIn — among others — have incorporated Flask into their development stacks. Flask 1.0.2 is currently available, the latest stable build released in May 2018. Benefits Flask is lightweight and non-intrusive, dropping rigid requirements found in other frameworks. Developers will enjoy its compatibility with outside tools and ORMs. Its dependencies are built with security in mind. Enjoy default protection from injection attacks, data integrity checks, and secure cookie generation on the client side. A built-in development server negates the need for configuring outside resources, cutting down on lead times and costs. Flask supports Python 3.4 and newer, while also supporting Python 2.7 and PyPy. Developers may freely use their preferred version, making API building simpler. Documentation is rich with examples and widespread, with the vast collection of use cases and sample code outlined. Drawbacks Companies may prefer other frameworks for larger MVC applications since Flask doesn’t ship with comprehensive bootstrapping tools and modules. Though Flask is highly flexible, the initial customization time can delay development and production. 2. Django A comprehensive power player by which other robust frameworks are measured. The household name in Python development, Django has surged in popularity since its 2005 debut. It’s maintained by the Django Software Foundation thanks to contributions from individuals and corporations, many of which rely on Django for development. Django has a bustling community, claiming over 11,600 members worldwide. Django has over 191,000 tagged questions on Stack Overflow. Developers can get involved in mailing lists, RSS feeds, an IRC channel, and more. Spotify, YouTube, and Instagram rely on Django for application and data management. This group is continually growing in conjunction with Django, which has released over 214 updates since its creation. Benefits The size of Django’s community is staggering — newcomers and veterans alike can expect plenty of guidance for even the most granular use cases. Templating, routing, forms, authentication, and management tools are included by default. Developers won’t have to go hunting for external tools, especially when third-party components can face compatibility issues. Simple constructs for users, loops, and conditionals allow developers to rapidly write numerous lines of new code. Django’s integration with MongoDB, DynamoDB, SQLite and more make it a powerhouse for managing immense data sets. For applications with large numbers of users, this is invaluable. A mature and optimized framework, Django is extremely fast and reliable right out of the box. Drawbacks Django separates new projects into individual components, using empty template files. Because Django presents new users with less example code, learning is trickier. New programmers may face issues packaging components together since guidance isn’t explicitly provided. The vast number of default tools makes it challenging for newcomers to get up to speed. 3. Pyramid The hybrid framework that brings the best of both worlds, big or small. Aiming to be neither too big nor not too small, Pyramid seeks to bridge the gap between frameworks like Django and Flask. It’s developed as part of the Pylons Project, and was released in 2008. Pyramid draws inspiration from both Django and other smaller frameworks. Developers can follow Pyramid’s progress on social media via Twitter and a Google group. Pyramid’s developers often participate in public events. Finally, developers keen on learning more about the framework may join the official IRC channel. Mozilla and Yelp are notable companies reliant on the Pyramid for development. The current version of Pyramid is 1.10, the tenth update since its debut. Benefits In contrast to Django, Pyramid provides ample guidance for file bundling, thus packaging your projects in a much more foolproof manner. This provides a safety net, especially for newcomers. Pyramid creates a fairly sizeable project template, yet provides ample starter code and skeletons to simplify development. Pyramid’s bootstrapping tool, pcreate, is compatible with numerous templates based on SQLAlchemy and ZODB. This flexibility swells with PyPi, which supports Google App Engine, Jinja 2, and jQuery Mobile. Pyramid allows developers to scale applications rapidly, with robust API support, URL mapping, and heavy extensibility via add ons. Context managers group requests and writes into logical groups, useful for high-traffic periods. Pyramid supports all supported versions of Python. Drawbacks Pyramid’s Chameleon template syntax can be relatively complicated. Lack of the for-else construct results in verbose strings, also true for form rendering. XHTML structuring, though parsable by editors, can seem foreign and complex to those migrating from Django. 4. Falcon A high-performance microservices framework focused on quality control. Falcon was built as a bare-metal framework and is optimized for microservices. With WSGI compliance, it’s made for compatibility with numerous servers and platforms. Kurt Griffiths created Falcon in 2013 and is a top contributor. However, a dedicated community provides extensive input. Newcomers to the Falcon framework can follow along with talks, podcasts, and blog posts. There are also chat rooms on Gitter for developers and users alike. Companies like LinkedIn and Rackspace utilize the framework for various projects. Documented on GitHub, Falcon has shipped 43 updates since launch, currently sitting at version 1.4.1. Benefits Falcon is OS agnostic and focusing on running efficiently on any given hardware, with framework flexibility. The framework partners harmoniously with Python 2.6, 2.7, and 3.4+. REST HTTP handlers provide request resolutions and easy state transitions. Source code development is tested extensively for errors. Falcon uses only two third-party dependencies. Using its default configuration, Falcon can make up to 19x more requests per second than Django under identical conditions. Drawbacks Falcon is not suitable for serving HTML pages. Lacks a built-in web server. Though documentation and tutorials are plentiful, it’s generally less comprehensive than those for frameworks like Flask. 5. Eve A medium-sized framework built to handle everything but the kitchen sink. A REST API framework focusing on web services, Eve is built upon Flask and Cerberus. Eve is fundamentally built with CRUD implementation and made to be more humanistic. The framework is written and maintained by Nicola Iarocci, concurrently with community contributions. It was released in early 2013. The project maintains an active presence on GitHub with 138 contributors. Developers may also join a mailing list to stay informed, alongside Eve’s IRC, Google Groups, and Stack Overflow. Since launch, Eve has been updated 33 times, and its current version is 0.8.2. Benefits Eve emphasizes REST and full-range CRUD compliance while providing necessary fallbacks by default. Known database collections are automatically as resource endpoints. These endpoints are customizable to each use case and can include additional fields without client input. Eve supports sub-resource endpoints and multi-item endpoints for enhanced URI flexibility. MongoDB is natively supported, and community extensions provide compatibility with SQL, Elasticsearch, and Neo4js. Filtering, sorting, resource pagination, and HATEOAS are supported by default. Drawbacks Eve is generally better for small to mid-sized projects, as large projects can be difficult to manage at scale. Because the framework is relatively minimalist, it may take some time to hunt down suitable extensions and optimal configurations. 6. CherryPy An object-oriented approach built with granular configuration potential. Another minimalist web framework, CherryPy is object-oriented and HTTP/1.1 compliant, CherryPy aims to promote speedy development while shrinking overall source codebases. It was built by Remi Delon and released in 2002. It’s now maintained by the CherryPy team and development community. CherryPy has a mailing list. Developers may also join the framework’s Google group, Gitter portal, or IRC channel. The CherryPy team is accepting commits and further contributions on GitHub. Netflix and Hulu use CherryPy as a building block for select projects. The current version is 18.1.0 — the 120th release in the development life cycle. Benefits Object-oriented programming keeps development time down while cutting down on codebase size. CherryPy has built-in tools for caching, sessions, authentication, and static content. Every component and resource is interchangeable, letting developers customize as they see fit. For developers working with multiple applications, each application can be configured independently. Single-line update methods allow global server configurations with simple mergers. CherryPy can serve both dynamic, user-dependent content as well as static resources. Built-in support for JSON encoding and decoding, for both requests and responses. Drawbacks Though some features like sessions are incorporated, they may not be enabled by default. Developers must remember to manually enable these configurations. If page handlers are not written correctly, users with permissions could potentially access any file stored on the server. 7. Bottle A microscopic, independent framework with ample versatility. Similar to Flask, Bottle is a WSGI micro-framework for API development. Unique to Bottle is its single-file module and has no dependencies apart from Python’s standard library. It is written and maintained by Marcel Hellkamp, originally released in 2009. Community contributions are vetted and accepted via GitHub. Bottle has a blog and a mailing list, and interested developers may also follow along on Twitter. A freenode chat provides an additional forum for discussion. Bottle has been used by Netflix to handle some core functions. The current version of Bottle is 0.12.16, and it has been updated 73 times since its release. Benefits Bottle is extremely lightweight and configurable, with support for mako, Jinja 2, and cheetah templates. A built-in HTTP development server supports paste, fapws3, bjoern, gae, cherrypy, and other WSGI servers. Intelligent routing accounts for cleaner, customizable, and logical URLs for requests and function calls. External libraries are unneeded, simplifying development and cutting down on cross-platform issues. Drawbacks An absolute path may be needed in addition to the template search path. In some cases, Bottle may otherwise fail to locate your templates. Developers must add patterns to placeholders to account for slashes within their syntax. Bottle may lose some data in transit when operating locally behind a reverse proxy or load balancer. A workaround may be required to ensure header integrity for the client. 8. Tornado A robust framework built to handle high traffic with minimal overhead. Both a web framework and asynchronous networking library, Tornado is built to support numerous simultaneous connections. It was originally developed at FriendFeed and debuted in 2010. Tornado is primarily maintained by Ben Darnell in conjunction with GitHub community contributions. Developers can track news and updates via mailing list and two separate Google groups. Tornado also claims a Stack Overflow following and maintains a wiki on GitHub. Tornado is currently updated to version 6.0, having shipped 56 updates since launch. Benefits With a non-blocking network I/O, Tornado can support tens of thousands of simultaneous connections, suitable for long polling, WebSockets, and more. Supports third-party login in conjunction with OpenID, OAuth, and Graph API (Google, Facebook, Twitter). Tornado can auto-reload server connections to detect and apply source file changes. Operates with WSGI web frameworks and servers. Drawbacks Because Tornado is asynchronous, running a WSGI app with its WSGIContainer is less scalable than using that app with a WSGI server (eg. gunicorn and uwsgi). Due to its relatively-novel approach to networking, there may be a learning curve associated with Tornado. No ORM support. The latest API insights straight to your inbox