Battle of the PaaS: Python Apps in the Cloud
Battle of the PaaS: Python Apps in the Cloud
This article is a comparison of various cloud hosting options for Python applications including GoogleCloud, AWS, and Heroku.
Join the DZone community and get the full member experience.Join For Free
Sensu is an open source monitoring event pipeline. Try it today.
In the early days of the web, web pages were static and did not change. Today, however, most websites you visit are like applications you might find on your desktop — they offer dynamic content that changes on the fly. Users can interact with the app and get different information from another user, all without leaving the same page.
Python has been, and still is, a popular language to build a web application stack to organize and display that data. In this article, we will examine several of the most popular Python Platform-as-a-Service (PaaS) platforms and evaluate their pros and cons.
You have several options for choosing a web host:
- Virtualized servers
- Platform as a service (PaaS)
- Infrastructure as a service (IaaS)
Bare-metal, IaaS, and virtualized servers are somewhat the same. You must start with a Linux-based server, then install the system packages, web server, WSGI server, Python environment and database.
One of the benefits of PaaS is the ability to deploy a project at no or low cost. You do not have to concern yourself with configuring the operating system or server setup. This speeds up your ability to deploy as compared to other options. On the other hand, if you are interested in developing your knowledge about the Python stack, a traditional server will give you more in-depth understanding. You will also keep more money in your wallet as you scale and have much more control over your environment. With that in mind, let’s review some of the well-known Python hosts and examine their similarities and differences.
Google App Engine
Google App Engine is an easy way to deploy your web app and not have to worry about large amounts of data processing and heavy usage loads. It will run in a secure environment, regardless of the operating system or server location. You can get a feel for how rapidly you can deploy to the platform by downloading a simple Hello World file to your computer, and then test the app with the development server that comes along with the App Engine Software Development Kit.
Google App Engine offers a standard environment and flexible environment options. The standard environment utilizes custom-made Google containers that are wrapped around your code, and that run on Google infrastructure. The flexible environment is still in beta and, instead of Google containers, it employs Docker containers to wrap the code.
The flexible environment is built on Google Compute Engine. Your app will scale, and the load will balance automatically in response to fluctuations in demand. The runtime is based on Debian Jessie, and you can locate the source code for the runtime on GitHub.
Amazon Web Services
Amazon Web Services has continually improved offerings over the last several years. You can use boto3, the Amazon Web Services Software Development Kit for Python, to rapidly deploy to AWS, and then combine your script, library or Python web app with Amazon services such as Amazon EC2, Amazon DynamoDB, Amazon S3 and others.
Boto3 offers two APIs. The first is a client API that lets you map to HTTP API operations. Resource APIs give you resource objects and collections that allow you to perform actions and tap attributes. Both APIs generate classes on a dynamic basis powered by JSON models, giving you rapid updates and stable consistency among all of the supported AWS services.
Boto3 was designed from the beginning to provide support for both Python 2 and 3 (specifically, versions 2.6.5+, 2.7, 3.3 and 3.4). Boto3 also has “waiters” that look for status changes in Amazon Web Services resources automatically. For instance, you can launch an instance of Amazon EC2 and employ a waiter to stand-by until running state is reached. Waiters are available on resource and client APIs.
Regardless of whether you use a Flask, Django or other Python framework, Heroku lets you deploy and scale your app the way you want. Heroku utilizes git as the method for deploying apps. When setting up an application on Heroku, it associates with a remote, usually called ‘heroku’ with the git repository aligned with your application. That means that to deploy the code you are using a command called ‘heroku’ much the same as you would ‘git push.’
However, that is not the only way to deploy to Heroku. You can integrate with GitHub and associate each additional pull request with a new app. You can also tap the power of Dropbox Sync, or create and release apps through the Heroku API.
Once the platform receives your source, it begins building the app. All of the publishing and infrastructures is handled automatically.
PythonAnywhere is a full Python environment that allows you to begin hosting your Python application for free. The basic level includes everything you need to host the code and your website without installing software or managing a server or Linux machine. It takes less than a minute to get started, and you can upgrade as you grow with paid plans that start as low as five dollars a month. This plan can easily accommodate a website that is getting around 10,000 hits every day. As the site grows in popularity, you can upgrade seamlessly to a bigger account.
There are installers available for a wide variety of frameworks, including Django, Bottle, web2py, Flask and most WSGI web frameworks. Custom and web developer accounts can host their dedicated domains at PythonAnywhere.
You can also develop your code in a web-based editor and store it on PythonAnywhere servers. It will preserve your session, so you can pick it up on another device where you left off from anywhere in the world. Your Python installation includes some popular libraries like Mechanize and BeautifulSoup.
Although you can get started at a low cost, you can be confident that the servers are powerful. All servers are hosted on Amazon EC2. Experiment with various simple programs at no charge to develop your concept. When you are ready to ramp up with heavier processing, you only invest in what you use, allowing you to tap into teraflops of power.
WebFaction is an inexpensive, Python-friendly web hosting provider. Python is available on all servers, and version 2.5 through 3.5 are already installed. The default version varies when you actuate the ‘python’ command, depending on the server. To figure out which default version is on your server, use ‘python -V.’ If you want to use a particular Python version, enter ‘pythonX.Y,’ with X and Y representing the Python version number. All Python modules and packages are distributed automatically as a Python Egg. Alternatively, they are distributed in archive form along with a ‘setup.py’ file, or as source ‘.py’ files in a collection.
All servers are pre-installed with CentOS 7. Servers are continually monitored for security and high performance. They are patched on the fly and backed up regularly (I expect this to be the case with any modern hosting provider, of course). You will get complete shell access to control databases and files.
Which Is the Right Host for You?
Choosing the right Python web host depends on your goals. If you want to get started without spending any money and have access to a variety of installers, including Flask and Django, PythonAnywhere is a good choice. The web-based editor gives you a quick way to develop ideas wherever you are without needing to launch your own development environment. Once your application is launched, you can easily upgrade down the road if it grows in popularity.
WebFaction is another good selection if you are operating with a slim budget. Every version of Python is pre-installed along with CentOS 7. It is a no muss, no fuss option that gets you up and running with shell access control.
Power users with some resources will more than likely turn to stalwarts such as Google App Engine and Amazon Web Services. Frameworks that run on GAE include Pyramid, Flask, web2py and Django. However, you are not limited to those. Every Python stack that supports WSGI can be utilized to build an app using a CGI adapter. The framework is uploaded alongside the application. You can also call Python third-party libraries.
Amazon Web Services allows you to combine your Python app with the powerful spectrum of Amazon services, including Amazon S3 and Elastic Cloud. Heroku seems to be a “fan favorite,” with some developers praising it for its flexibility and deployment method options. If you are experimenting with new apps, or just want to save money, go with PythonAnywhere or WebFaction. Serious developers with a budget should choose Heroku, Google App Engine or Amazon Web Services.
Published at DZone with permission of Omed Habib , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.