Python Web Examples

10 Famous Websites Built Using Python – Learn to code in 30 …

Chris Castiglione Follow
Teacher at One Month. Faculty at Columbia University where I teach Digital Literacy. I write about coding, the internet, and social impact.
January 10, 2020
3 min read
There are tens of thousands of Python websites on the internet. Python is a powerful programming language created by Guido van Rossum in 1991. Python is a popular language with both beginners and seasoned developers.
Many of today’s most successful tech companies are choosing Python for the back-end of their website. Let’s take a look at 10 famous websites built using Python.
1. Instagram
Instagram, the world’s biggest online photo-sharing app, uses Python on its backend. According to Instagram’s engineering team,
Instagram currently features the world’s largest deployment of the Django web framework, which is written entirely in Python.
Read more about how Instagram uses Python on the Instagram blog.
2. Google
Google is the most widely used search engine in the world with over 75% of the market share. Longtime Google engineer, Alex Martelli, explained how Google got started using Python in their tech stack,
It all got started, I believe, because the very earliest Googlers (Sergey, Larry, Craig, …) made a good engineering decision: “Python where we can, C++ where we must. ”
Read more about why the Google tech stack is built using Python.
3. Spotify
Spotify allows instant listening to specific tracks or albums with virtually no buffering delay. The app was launched in 2008 and has since then has reached over 75 million paid subscribers.
While Spotify’s website is build using WordPress, the Spotify app is built using Python. Spotify engineer Geoff van der Meer explains how Spotify used Python to code the app’s backend:
Spotify’s backend consists of many interdependent services, connected by [its] own messaging protocol over ZeroMQ. Around 80% of these services are written in Python.
Read more about how Spotify uses Python.
4. Netflix
Netflix is the world’s leading internet television network with more than 33 million members in 40 countries enjoying more than one billion hours of TV shows and movies per month, including Netflix original series. According to the Netflix technology blog,
Developers at Netflix have the freedom to choose the technologies best suited for the job. More and more, developers turn to Python due to its rich batteries-included standard library, succinct and clean yet expressive syntax, large developer community, and the wealth of third party libraries one can tap into to solve a given problem.
Read more about how and why Netflix uses Python.
5. Uber
Uber, the ridesharing service, completes over 15 million trips daily. According to Uber engineers,
At the lower levels, Uber’s engineers primarily write in Python,, Go, and Java. We started with two main languages: for the Marketplace team, and Python for everyone else. These first languages still power most services running at Uber today.
Learn more about the Uber tech stack and how they use of Python.
6. Dropbox
Dropbox is a home for all your photos, docs, videos, and files.
Have you ever wondered, how does an app like Dropbox scale from 2000 users to 200M users? According to Rajiv Eranki, previously Head of Server Engineering at Dropbox, they used Python for everything.
In 2012, Dropbox hired the man who created Python, Guido van Rossum, away from Google. As of this writing, Rossum is still employed at Dropbox, making sure that Dropbox’s Python stack is one of the most efficient in the industry.
Read more about how Dropbox is using Python.
7. Pinterest
Pinterest is a social bookmarking site where users collect and share photos of their favorite events, interests, and hobbies. According to Pinterest co-founder Paul Sciarra,
We use python + heavily-modified Django at the application layer. Tornado and (very selectively) as web-servers.
Find out more about Pinterest’s tech stack.
8. Instacart
Instacart guarantees groceries delivered from the stores you love in one hour. With more than 500, 000 users and 2 million in revenue, it is quickly becoming one of the most popular grocery delivery apps. According to an interview with Instacart’s engineering team,
We have a data science team that works in both Python and R […] In the case of demand forecasting, we have Python or R code that does the estimates, that reads all the data, comes up with how many shoppers we’re going to need for the next week or two, and then writes those values.
Read more about Instacart’s stack and why they use Python.
9. reddit
Reddit has 330 million monthly active users. According to an interview at PyCon with Reddit co-founders Steve Huffman and Alexis Ohanian,
The biggest thing that has kept us on Python … well, there are two huge things. One are the libraries. […] The other thing that keeps us on Python, and this is the major thing, is how readable and writable it is. When we hire new employees … I don’t think we’ve yet hired an employee who knew Python. I just say, “everything you write needs to be in Python. ” Just so I can read it. And it’s awesome because I can see from across the room, looking at their screen, whether their code is good or bad. Because good Python code has a very obvious structure. And that makes my life so much easier.
Read more about why Reddit uses Python.
10. lyft
Lyft is the fastest growing rideshare company in the United States and is available in more than 200 cities, facilitating 14 million rides per month.
At a San Francisco Meetup in 2018, Lyft software engineer Roy Williams told the crowd,
Lyft is a big fan of Python. It’s quite common for services to utilize NumPy, Pandas, and PuLP to serve requests via Flask, Gevent, and Gunicorn. We use SciPy to fight fraud, we use Salt to provision hosts.
Watch Roy Williams’ talk on how and why Lyft uses Python 3 in their tech stack.
Ready to learn Python? You can join over 60, 000 students at One Month where we offer a 30-day Learn Python Online Bootcamp. The course is for absolute beginners, and we offer live human support for when you have questions.
Exploring The Best Python Applications And Website Examples

Exploring The Best Python Applications And Website Examples

Table of contentsTop 30 Python Web Application ExamplesDropboxInstagramIBMNetflixSpotifyRedditFacebookGoogleUberPinterestInstacartLyftYouTubeQuoraYahoo MapsHipmunkDisqusWashington PostNASABitbucketReddit GiftsPreziPitchForkEventbriteMozillaSurvey MonkeyBitlyOnionMahaloBitTorrentConclusion
Python was introduced in the year 1991 by Guido van Rossum. Over the last two decades, it has improved a lot and won the hearts of a lot of developers. Today, we’re going to focus on the Python Application and Website Examples
Currently, there are a vast number of websites & apps that are running on Python. The success of these websites and apps indicates the presence of Python Framework.
Python is also referred to as an advanced programming language that focuses on the real-value of code readability. It allows python dedicated developers to achieve their goals with less code.
The most important feature why developers choose Python for their project is its dynamic type system and automatic memory management.
In this blog, we will provide you with 30 examples of Python Applications & websites that have become successful in the last few years.
Top 30 Python Web Application Examples
Who doesn’t have heard of Dropbox? The company introduced the concept of storing files online, took it to the next level, built a highly-dynamic product that adds value to users’ lives, and generated revenue from the process.
Basically, the app allows users to store photos, videos, documents, and other files. A Leading Python Development Company can help you to develop such apps.
Then access all the things from any device provided the user should be connected to the internet. As of 2019, there are more than 600 Million users of Dropbox.
The company used Python to build the backend as well as the client desktop software. With the help of the Django framework, developers integrated the history option, synchronized accounts around various devices, and then lastly included a quick file sharing option.
Instagram is the leading photo-sharing app across the globe and Facebook acquired it for a billion dollars in cash and stock in 2012. Earlier, Instagram was just an essential website developed using Python.
Later, the developers deployed it to the world’s biggest Django Web framework, which allowed them to emphasize the UI/UX part more without thinking much about the technology. Moreover, Instagram is one of the best Python Applications Examples.
IBM, also known as International Business Machines Corporation, is a leading tech giant that offers hardware, software, cloud-based services, and cognitive computing.
From earlier built mainframes to M Keyboards and ThinkPads to newly invented Watson, IBM has been developing wonderful things for the tech industry for the last 20 years.
IBM chose Python for its AI & other services because it offers a fast method of implementation and testing current as well as old algorithms.
Also, this Python Applications Examples is useful for assembling various physics codes together, which is mainly conducted in leading U. S laboratories.
Netflix has started it’s journey initially in the form of a DVD-by-mail service and later emerged as a leading streaming video service provider to millions of users across the world.
According to Statista, as of the first quarter of 2020, Netflix has more than 69. 97 million paid subscribers only in the United States and Canada.
The majority of developers working in Netflix have switched over to Python due to its clean & clear syntax, massive developer community, and highly-rich third-party libraries that help them achieve their business objectives & goals.
Using Python, Netflix has built a highly efficient recommendation and analytics engine, with which they can deliver better suggestions and analyze the type of content the user wants.
Spotify is one of the best examples of Python applications. It is the leading music streaming service across the globe that enables you to find & listen to particular tracks, albums, podcasts, etc. for free.
Spotify decided to build its app using Python due to its increased development speed and enhanced analytics. Due to Python, Spotify can carry out different functions such as Ratio and Discover that depends heavily on the music preferences of users.
Reddit is mostly referred to as the front page of the internet. In other words, it is the biggest community of users on the web. It has more than 430 million active users as of 2019.
Initially, Reddit was written in Common Lisp. But later, the company determined to switch the code to Python due to its built-in libraries, adaptability, and simplicity. Out of various Python app examples, Reddit stands out to be unique.
Reddit allows all the registered users to post text, videos, GIFs, Questions, on numerous categories. Here content is promoted with the help of the voting approach. So, it is one of the finest Python Application Examples.
Facebook is the leading social media giant worldwide, with more than 2. 5 billion monthly active users. It has an excellent tech stack that consists of a vast number of languages and technologies. Facebook is one of the popular Apps Made with Python.
Moreover, Python holds 21% of Facebook’s Infrastructure codebase. Also, it is the third most popular language used by Facebook after PHP & C++. Python is useful to control millions of posts, photos, videos, stories, etc. shared on the platform.
Engineers at Facebook choose to work with Python as it enables them to handle a wide number of libraries, communicate with the APIs, and increase their engineering process.
Google is the leading search engine in the market, with over 87% of the market share. It provides a wide range of services from video streaming, music, books, apps, hardware, software, etc.
Basically, the company works on the main principle, which states, “Python where we can, C++ where we must. ”
It requires a high amount of computational power to manage the most robust search engine in the world. Hence, Google turned over to Python at its core and also to operate different apps along with its main site.
Using Python, Google can analyze the requirements of the search and deliver better results. So, it is one of the classic Python Application Examples.
Uber has initiated a ride-hailing service and later evolved by providing a wide number of services such as peer-to-peer ride-sharing, food delivery, bicycle-sharing, etc. It provides more than 14 million trips daily.
It is providing its services in 65 countries and 600+ cities across the globe. The company has completed 10+ billion rides.
Experts at Uber prefer to write code using Python,, Go, and Java. Out of which, they primarily use for Marketplace and Python for all the other things.
Developers decided to integrate Python because it allows them to control a massive amount of data with ease. Also, it is efficient, safe, and scalable.
Pinterest is one of the best Python website examples. It is also known as one of the leading websites running on Django. Due to this Python framework, registered users can subscribe to other users on the platform and share their boards and pins anywhere on the internet.
As of 2019, Pinterest was getting 322 million user visits every month on its app. The company uses Python to provide user-friendly experience and scale at a phenomenal level and maintain its reputation in the market.
Instacart promises to deliver groceries from your desired store on the same day. The company is offering grocery delivery and pick-up service, only the United States and Canada.
Instacart has partnered with 25, 000+ grocery stores present across 5, 500 cities in North America. With more than 500, 000 users and valued at around $8 billion, it is on its way to becoming one of the leading grocery delivery apps.
Instacart opts for Python for developing their grocery system, as it allows them to analyze all the data and then make a list of shoppers that will be required for the next 2-3 weeks and then mention those values.
Lyft is one of the most popular ride-sharing companies, providing its services in more than 300 cities in the United States and Canada.
As of January 2018, more than 23 million users have used Lyft and it has completed 1 billion+ rides.
One of the Lyft Software engineers stated that they are more inclined towards Python and use different services like Numpy, PuLp, Salt, SciPy, Pandas, etc., to serve their customers in the best possible manner.
YouTube is one of the most popular Python website examples. It was developed using PHP earlier, but later, considering the demand of users and its growth, the team decided to switch over to Django Community.
Both YouTube Websites, as well as apps, offer a highly interactive user experience. On YouTube, a wide variety of content is available on every topic.
With the help of Python, YouTube introduced a feature of live streaming and embedding live streaming.
Do you have a question in mind? If yes, then post it on Quora and get an answer from anyone across the world.
Briefly, Quora is the leading Question-Answer Platform that enables all the internet users to ask questions, answer & edit them in the form of facts or opinions.
The community is organizing all the relevant answers to the questions. It has 300 million active users per month and around 15, 000+ questions are answered daily.
Developers at Quora have found that Python has a lot of potential to take their platform to their next level; hence, they decided to turn over to Python. So, it is one of the popular Python Application Examples.
Yahoo Maps
Even though Yahoo Maps has not remained as popular as it’s competitors, it comprises some incredible features like address book, live traffic, finds on the map, driving directions, draggable maps, widgets, etc.
To provide all these features, Yahoo has used Python in Yahoo Maps. Besides this, Yahoo has used Python to create some other useful programs too.
Hipmunk is basically a travel website. It allows you to compare the various travel packages around the globe and helps you to find the best option for you. Python has played an integral role in the development this amazing website.
Disqus is one of the best programs made with Python’s Django framework. The leading comment hosting service provider offers an interface that a developer can integrate into websites or blogs, analyze audience activity, and offer personalized ad serving.
Using the Django Performance Tips, the Disqus team built a website efficiently and then scaled it for a wide number of users.
According to May 2019, Disqus has reached 17 million page views per month with 2 billion unique visitors from around 191 countries and serves 50 million users per month.
Disqus has helped the site owners to approach their communities in the best possible manner.
Washington Post
Python’s Django framework was created to fulfill the fast-paced newsroom’s demands and is still the first choice by a vast number of news apps. Out of which, The Washington Post is one of the best Python Web App Examples.
The Washington Post opted for Django because it allows them not only to serve a wider audience but also to scale their website anytime possible.
NASA stands for National Aeronautics and Space Administration and its website is mainly used to discover the latest news, photos, videos, etc. in their space exploration.
Even though NASA is not famous like Facebook and Twitter, it serves more than 2 million users every month. To serve huge traffic and provide better user experience along with utmost security, NASA chooses the Django web framework.
Earlier people used to store their source code on the machine. With the launch of GitHub, source code management has become really easy. Later, BitBucket was launched in 2008, and it has also dominated the market level.
BitBucket is a cloud-based hosting platform for source code management and collaboration. It allows developers to create a repository, push code, add collaborators, look after the commits, and pull requests, etc.
As of 2019, BitBucket has crossed 10 million registered users and consists of 28 million repositories. BitBucket switched over to Django because it can serve millions of users and offers ready-to-implement solutions.
Reddit Gifts
Leading social news aggregator and discussion website Reddit has released an online anonymous gift exchange platform known as Reddit Gifts. It is an excellent Python Website Examples.
In General, the site allows users to connect from any part of the globe and then promote a gift exchange with the other user. The website uses the Django web framework to provide a highly-intuitive experience to the users.
Prezi is one of the Applications That Use Python. It is a presentation software that leverages a big virtual canvas that users can zoom in and out to view particular text, content, or ideas.
Prezi also allows users to add images and videos to make their presentations engaging and user-friendly. One of the best examples of programs written in Python.
Pitchfork is regarded as the highly-trusted voice in music. The platform is built using Python’s Django framework. It allows users to explore and experience music like never before.
The independent music platform comprises extensive reviews and analyses of people, trends, news, events, interviews, etc. In short, Pitchfork has transformed music journalism in the last two decades.
Eventbrite is a one-stop solution to catch up on the latest events, purchase tickets, discuss events & lastly, promote them.
Initially, the platform was developed using Python & various other frameworks; however, the company later shifted to Django, a Python-based open-source framework.
The company made this decision to serve a massive amount of audience and make interactions better. Considering Django’s better scalability, the company can now control its traffic and provide regular updates to the users.
Read also: Exploring The Pros & Cons of Python Web Development
Mozilla is one of the leading browsers across the sphere. Initially, Mozilla was built using PHP & CakePHP.
Later, with the increasing number of traffic and the ability to offer high-performance, Mozilla decided to integrate Python & Django in its technology stack.
Currently, the Mozilla support website and all the add-ons on the browser are backed-up by Django.
Survey Monkey
Survey Monkey is the leading survey company with 98% of Fortune 500 companies, depending on it for their consumer’s data. It is a cloud-based software as a service company that was introduced by Ryan Finley in 1999.
Initially, the company was using a monolithic web app. Even though the system was operating flawlessly, it was slow in adding, testing, and deploying various functionalities.
Hence, SurveyMonkey resolved this issue by writing its entire application in Python & separating primary features in a wide number of services.
Bitly is one of the most well-known link management systems. Peter Stren in 2008 introduces it to the world. It shortens more than 600 million links in a year. It is also one of the popular applications made with Python.
Bitly allows businesses to form short-branded links, share it across different platforms, and monitor their performance via analytics.
The onion is one of the best Python website examples. It is the ultimate source for anyone looking for satirical posts on local, national, or international news. It is a highly read newspaper all over the world, that has millions of visitors every month.
Mahlo is basically a Question and Answer website. It is not as famous or popular as Quora but it has its own significance. The site was established in2007 and its slogan is “Learn Anything. ”
BitTorrent is mainly a communication protocol for peer-to-peer file sharing and it helps to share data and other things on the web in a decentralized manner. It was released in 2001 by Bram Cohen and David Harisson.
One of the best applications made with Python. Bit Torrent consists of a huge database of knowledge, media, and content.
Using Python, it provides a vast number of features such as torrent downloads in bulk, manage torrents, save network resources, etc.
The above examples of applications made with Python clearly indicates that Python is the go-to-choice of leading tech-giants and various other companies worldwide. It is one of the most robust languages for building websites and mobile applications.
If you have an incredible idea and want to convert it into a website, reach out to a python developer. We will be more than happy to brainstorm your idea in detail and deliver you the best Python application.
Python Web Applications: Deploy Your Script as a Flask App

Python Web Applications: Deploy Your Script as a Flask App

You wrote a Python script that you’re proud of, and now you want to show it off to the world. But how? Most people won’t know what to do with your file. Converting your script into a Python web application is a great solution to make your code usable for a broad audience.
In this tutorial, you’ll learn how to go from a local Python script to a fully deployed Flask web application that you can share with the world.
By the end of this tutorial, you’ll know:
What web applications are and how you can host them online
How to convert a Python script into a Flask web application
How to improve user experience by adding HTML to your Python code
How to deploy your Python web application to Google App Engine
In addition to walking through an example project, you’ll find a number of exercises throughout the tutorial. They’ll give you a chance to solidify what you’re learning through extra practice. You can also download the source code that you’ll use to build your web application by clicking the link below:
Brush Up on the Basics
In this section, you’ll get a theoretical footing in the different topics that you’ll work with during the practical part of this tutorial:
What types of Python code distribution exist
Why building a web application can be a good choice
What a web application is
How content gets delivered over the Internet
What web hosting means
Which hosting providers exist and which one to use
Brushing up on these topics can help you feel more confident when writing Python code for the Web. However, if you’re already familiar with them, then feel free to skip ahead, install the Google Cloud SDK, and start building your Python web app.
Distribute Your Python Code
Bringing your code to your users is called distribution. Traditionally, there are three different approaches you can use to distribute your code so that others can work with your programs:
Python library
Standalone program
Python web application
You’ll take a closer look at each of these approaches below.
Python Library
If you’ve worked with Python’s extensive package ecosystem, then you’ve likely installed Python packages with pip. As a programmer, you might want to publish your Python package on PyPI to allow other users to access and use your code by installing it using pip:
$ python3 -m pip install
After you’ve successfully published your code to PyPI, this command will install your package, including its dependencies, on any of your users’ computers, provided that they have an Internet connection.
If you don’t want to publish your code as a PyPI package, then you can still use Python’s built-in sdist command to create a source distribution or a Python wheel to create a built distribution to share with your users.
Distributing your code like this keeps it close to the original script you wrote and adds only what’s necessary for others to run it. However, using this approach also means that your users will need to run your code with Python. Many people who want to use your script’s functionality won’t have Python installed or won’t be familiar with the processes required to work directly with your code.
A more user-friendly way to present your code to potential users is to build a standalone program.
Standalone Program
Computer programs come in different shapes and forms, and there are multiple options for transforming your Python scripts into standalone programs. Below you’ll read about two possibilities:
Packaging your code
Building a GUI
Programs such as PyInstaller, py2app, py2exe, or Briefcase can help with packaging your code. They turn Python scripts into executable programs that can be used on different platforms without requiring your users to explicitly run the Python interpreter.
While packaging your code can resolve dependency problems, your code still just runs on the command line. Most people are used to working with programs that provide a graphical user interface (GUI). You can make your Python code accessible to more people by building a GUI for it.
While a standalone GUI desktop program can make your code accessible to a wider audience, it still presents a hurdle for people to get started. Before running your program, potential users have a few steps to get through. They need to find the right version for their operating system, download it, and successfully install it. Some may give up before they make it all the way.
It makes sense that many developers instead build web applications that can be accessed quickly and run on an Internet browser.
Python Web Application
The advantage of web applications is that they’re platform independent and can be run by anyone who has access to the Internet. Their code is implemented on a back-end server, where the program processes incoming requests and responds through a shared protocol that’s understood by all browsers.
Python powers many large web applications and is a common choice as a back-end language. Many Python-driven web applications are planned from the start as web applications and are built using Python web frameworks such as Flask, which you’ll use in this tutorial.
However, instead of the web-first approach described above, you’re going to take a different angle. After all, you weren’t planning to build a web application. You just created a useful Python script, and now you want to share with the world. To make it accessible to a broad range of users, you’ll refactor it into a web application and then deploy it to the Internet.
It’s time to go over what a web application is and how it’s different from other content on the Web.
Learn About Python Web Applications
Historically, websites had fixed content that was the same for every user who accessed that page. These web pages are called static because their content doesn’t change when you interact with them. When serving a static web page, a web server responds to your request by sending back the content of that page, regardless of who you are or what other actions you took.
You can browse an example of a static website at the first URL that ever went online, as well as the pages it links to:
The history of the WWW
Such static websites aren’t considered applications since their content isn’t generated dynamically by code. While static sites used to make up all of the Internet, most websites today are true web applications, which offer dynamic web pages that can change the content they deliver.
For instance, a webmail application allows you to interact with it in many ways. Depending on your actions, it can display different types of information, often while staying in a single page:
A single-page Webmail application
Python-driven web applications use Python code to determine what actions to take and what content to show. Your code is run by the web server that hosts your website, which means that your users don’t need to install anything. All they need to interact with your code is a browser and an Internet connection.
Getting Python to run on a website can be complicated, but there are a number of different web frameworks that automatically take care of the details. As mentioned above, you’ll build a basic Flask application in this tutorial.
In the upcoming section, you’ll get a high-level perspective on the main processes that need to happen to run your Python code on a server and deliver a response to your users.
Review the HTTP Request-Response Cycle
Serving dynamic content over the Internet involves a lot of different pieces, and they all have to communicate with one another to function correctly. Here’s a generalized overview of what takes place when a user interacts with a web application:
Sending: First, your user makes a request for a particular web page on your web app. They can do this, for example, by typing a URL into their browser.
Receiving: This request gets received by the web server that hosts your website.
Matching: Your web server now uses a program to match the user’s request to a particular portion of your Python script.
Running: The appropriate Python code is called up by that program. When your code runs, it writes out a web page as a response.
Delivering: The program then delivers this response back to your user through the web server.
Viewing: Finally, the user can view the web server’s response. For example, the resulting web page can be displayed in a browser.
This is a general process of how content is delivered over the Internet. The programming language used on the server, as well as the technologies used to establish that connection, can differ. However, the concept used to communicate across HTTP requests and responses remains the same and is called the HTTP Request-Response Cycle.
To allow Flask to handle requests on the server side, you’ll need to find a place where your Python code can live online. Storing your code online to run a web application is called web hosting, and there are a number of providers offering both paid and free web hosting.
Choose a Hosting Provider: Google App Engine
When choosing a web hosting provider, you need to confirm that it supports running Python code. Many of them cost money, but this tutorial will stick with a free option that’s professional and highly scalable yet still reasonable to set up: Google App Engine.
There are a number of other free options, such as PythonAnywhere,, or Heroku that you can explore later on. Using Google App Engine will give you a good start in learning about deploying Python code to the web as it strikes a balance between abstracting away complexity and allowing you to customize the setup.
Google App Engine is part of the Google Cloud Platform (GCP), which is run by Google and represents one of the big cloud providers, along with Microsoft Azure and Amazon Web Services (AWS).
To get started with GCP, download and install the Google Cloud SDK for your operating system. For additional guidance beyond what you’ll find in this tutorial, you can consult Google App Engine’s documentation.
The Google Cloud SDK installation also includes a command-line program called gcloud, which you’ll later use to deploy your web app. Once you’re done with the installation, you can verify that everything worked by typing the following command into your console:
You should receive a text output in your terminal that looks similar to the one below:
app-engine-python 1. 9. 91
bq 2. 0. 62
cloud-datastore-emulator 2. 1. 0
core 2020. 11. 13
gsutil 4. 55
Your version numbers will probably be different, but as long as the gcloud program is successfully found on your computer, your installation was successful.
With this high-level overview of concepts in mind and the Google Cloud SDK installed, you’re ready to set up a Python project that you’ll later deploy to the Internet.
Build a Basic Python Web Application
Google App Engine requires you to use a web framework for creating your web application in a Python 3 environment. Since you’re trying to use a minimal setup to get your local Python code up on the Internet, a microframework such as Flask is a good choice. A minimal implementation of Flask is so small that you might not even notice that you’re using a web framework.
The application you’re going to create will rely on several different files, so the first thing you need to do is to create a project folder to hold all these files.
Set Up Your Project
Create a project folder and give it a name that’s descriptive of your project. For this practice project, call the folder hello-app. You’ll need three files inside this folder:
contains your Python code wrapped in a minimal implementation of the Flask web framework.
lists all the dependencies your code needs to work properly.
helps Google App Engine decide which settings to use on its server.
While three files might sound like a lot, you’ll see that this project uses fewer than ten lines of code across all three files. This represents the minimal setup you need to provide to Google App Engine for any Python project you may launch. The rest will be your own Python code. You can download the complete source code that you’ll use in this tutorial by clicking the link below:
Next, you’ll take a look at the content of each of the files starting with the most complex one,
is the file that Flask uses to deliver your content. At the top of the file, you import the Flask class on line 1, then you create an instance of a Flask app on line 3:
1from flask import Flask
3app = Flask(__name__)
6def index():
7 return “Congratulations, it’s a web app! ”
After you create the Flask app, you write a Python decorator on line 5 called that Flask uses to connect URL endpoints with code contained in functions. The argument to defines the URL’s path component, which is the root path (“/”) in this case.
The code on lines 6 and 7 makes up index(), which is wrapped by the decorator. This function defines what should be executed if the defined URL endpoint is requested by a user. Its return value determines what a user will see when they load the page.
In other words, if a user types the base URL of your web app into their browser, then Flask runs index() and the user sees the returned text. In this case, that text is just one sentence: Congratulations, it’s a web app!
You can render more complex content, and you can also create more than one function so that users can visit different URL endpoints in your app to receive different responses. However, for this initial implementation, it’s fine to stick with this short and encouraging success message.
The next file to look at is Since Flask is the only dependency of this project, that’s all you need to specify:
If your app has other dependencies, then you’ll need to add them to your file as well.
Google App Engine will use to install the necessary Python dependencies for your project when setting it up on the server. This is similar to what you would do after creating and activating a new virtual environment locally.
The third file,, helps Google App Engine set up the right server environment for your code. This file requires only one line, which defines the Python runtime:
The line shown above clarifies that the right runtime for your Python code is Python 3. 8. This is enough for Google App Engine to do the necessary setup on its servers.
You can use Google App Engine’s file for additional setup, such as adding environment variables to your application. You can also use it to define the path to static content for your app, such as images, CSS or JavaScript files. This tutorial won’t go into these additional settings, but you can consult Google App Engine’s documentation on the Configuration File if you want to add such functionality.
These nine lines of code complete the necessary setup for this app. Your project is now ready for deployment.
However, it’s good practice to test your code before putting it into production so you can catch potential errors. Next, you’ll check whether everything works as expected locally before deploying your code to the Internet.
Test Locally
Flask comes packaged with a development web server. You can use this development server to double-check that your code works as expected. To be able to run the Flask development server locally, you need to complete two steps. Google App Engine will do the same steps on its servers once you deploy your code:
Set up a virtual environment.
Install the flask package.
To set up a Python 3 virtual environment, navigate to your project folder on your terminal and type the following command:
This will create a new virtual environment named venv using the version of Python 3 that you have installed on your system. Next, you need to activate the virtual environment by sourcing the activation script:
$ source venv/bin/activate
After executing this command, your prompt will change to indicate that you’re now operating from within the virtual environment. After you successfully set up and activate your virtual environment, you’re ready to install Flask:
$ python3 -m pip install -r
This command fetches all packages listed in from PyPI and installs them in your virtual environment. In this case, the only package installed will be Flask.
Wait for the installation to complete, then open up and add the following two lines of code at the bottom of the file:
if __name__ == “__main__”:
(host=”127. 1″, port=8080, debug=True)
These two lines tell Python to start Flask’s development server when the script is executed from the command line. It’ll be used only when you run the script locally. When you deploy the code to Google App Engine, a professional web server process, such as Gunicorn, will serve the app instead. You won’t need to change anything to make this happen.
You can now start Flask’s development server and interact with your Python app in your browser. To do so, you need to run the Python script that starts the Flask app by typing the following command:
Flask starts up the development server, and your terminal will display output similar to the text shown below:
* Serving Flask app “main” (lazy loading)
* Environment: production
WARNING: This is a development server.
Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 315-059-987
This output tells you three important pieces of information:
WARNING: This is Flask’s development server, which means you don’t want to use it to serve your code in production. Google App Engine will handle that for you instead.
Running on This is the URL where you can find your app. It’s the URL for your localhost, which means the app is running on your own computer. Navigate to that URL in your browser to see your code live.
Press CTRL+C to quit: The same line also tells you that you can exit the development server by pressing Ctrl+C on your keyboard.
Follow the instructions and open a browser tab at. You should see a page displaying the text that your function returns: Congratulations, it’s a web app!
You can use Flask’s development server to inspect any changes that you make to the code of your Python app. The server listens to changes you make in the code and will automatically reload to display them. If your app doesn’t render as you expect it to on the development server, then it won’t work in production either. So make sure that it looks good before you deploy it.
Also keep in mind that even if it works well locally, it might not work quite the same once deployed. This is because there are other factors involved when you deploy your code to Google App Engine. However, for a basic app such as the one you’re building in this tutorial, you can be confident that it’ll work in production if it works well locally.
Change the return value of index() and confirm that you can see the change reflected in your browser. Play around with it. What happens when you change the return value of index() to HTML code, such as


, instead of using a plain text string?
After having checked your setup and the code’s functionality on your local development server, you’re prepared to deploy it to Google App Engine.
Deploy Your Python Web Application
It’s finally time to bring your app online. But first, your code needs a place to live on Google’s servers, and you need to make sure that it gets there safely. In this section of the tutorial, you’ll work on completing the necessary deployment setups both in the cloud and locally.
Set Up on Google App Engine
Read through the setup process below step by step. You can compare what you see in your browser with the screenshots. The project name used in the example screenshots is hello-app.
Start by signing in to the Google Cloud Platform. Navigate to the dashboard view, where you’ll see a toolbar at the top of the window. Select the downward-facing arrow button toward the left side of the toolbar. This will pop up a modal containing a list of your Google projects:
The modal displays a list of your projects. The list may be empty if you haven’t created any projects yet. On the top right of that modal, find the NEW PROJECT button and click it:
Clicking NEW PROJECT will redirect you to a new page where you can decide on a name for your project. This name will appear in the URL of your application, which will look similar to. Use hello-app as the name for this project to stay consistent with the tutorial:
You can see your project ID below the Project name input field. The project ID consists of the name you entered and a number that Google App Engine adds. In the case of this tutorial, you can see that the project ID is hello-app-295110. Copy your personal project ID since you’ll need it later on for deploying.
You can now click CREATE and wait for the project to be set up on Google App Engine’s side. Once that’s done, a notification will pop up telling you that a new project has been created. It also gives you the option to select it. Go ahead and do that by clicking SELECT PROJECT:
Clicking SELECT PROJECT will redirect you to the main page of your new Google Cloud Platform project. It looks like this:
From here, you want to switch to the dashboard of Google App Engine. You can do that by clicking the hamburger menu on the top left, scrolling down to select App Engine in the first list, then selecting Dashboard on the top of the next pop-up list:
This will finally redirect you to the Google App Engine dashboard view of your new project. Since the project is empty so far, the page will look similar to this:
When you see this page, it means you have completed setting up a new project on Google App Engine. You’re now ready to head back to the terminal on your computer and complete the local steps necessary to deploy your app to this project.
Set Up Locally for Deployment
After successfully installing the Google Cloud SDK, you have access to the gcloud command-line interface. This program comes with helpful instructions that guide you through deploying your web app. Start by typing the command that was suggested to you when you created a new project on the Google App Engine website:
As you can see in the bottom-right corner of the page, Google App Engine suggests a terminal command to deploy your code to this project. Open up your terminal, navigate to your project folder, then run the suggested command:
When you execute this command without any previous setup, the program will respond with an error message:
You do not currently have an active account selected.
Please run:
$ gcloud auth login
to obtain new credentials.
If you have already logged in with a different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
You receive this error message because you can’t deploy any code to your Google App Engine account unless you prove to Google that you’re the owner of that account. You’ll need to authenticate with your Google App Engine account from your local computer.
The gcloud command-line app already provided you with the command that you need to run. Type it into your terminal:
This will start the authentication process by generating a validation URL and opening it up in your browser. Complete the process by selecting your Google account in the browser window and granting Google Cloud SDK the necessary privileges. After you do this, you can return to your terminal, where you’ll see some information about the authentication process:
Your browser has been opened to visit:

You are now logged in as [<>].
Your current project is [None]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
If you see this message, then the authentication was successful. You can also see that the command-line program again offers you helpful information about your next step.
It tells you that there is currently no project set, and that you can set one by running gcloud config set project PROJECT_ID. Now you’ll need the project ID that you noted earlier.
Be sure to replace hello-app-295110 with your own project ID when running the suggested command:
$ gcloud config set project hello-app-295110
Your terminal will print out a short feedback message that the project property has been updated. After successfully authenticating and setting the default project to your project ID, you have completed the necessary setup steps.
Run the Deployment Process
Now you’re ready to try the initial deployment command a second time:
The gcloud app fetches your authentication credentials as well as the project ID information from the default configuration that you just set up and allows you to proceed. Next, you need to select a region where your application should be hosted:
You are creating an app for project [hello-app-295110].
WARNING: Creating an App Engine application for a project is
irreversible and the region cannot be changed.
More information about regions is at
Please choose the region where you want your App Engine application
[1] asia-east2
[2] asia-northeast1
[3] asia-northeast2
[4] asia-northeast3
[5] asia-south1
[6] asia-southeast2
[7] australia-southeast1
[8] europe-west
[9] europe-west2
[10] europe-west3
[11] europe-west6
[12] northamerica-northeast1
[13] southamerica-east1
[14] us-central
[15] us-east1
[16] us-east4
[17] us-west2
[18] us-west3
[19] us-west4
[20] cancel
Please enter your numeric choice:
Enter one of the numbers that are listed on the left side and press Enter.
After you enter a number, the CLI will continue with the setup process. Before deploying your code to Google App Engine, it’ll show you an overview of what the deployment will look like and ask you for a final confirmation:
Creating App Engine application in project [hello-app-295110]
and region [europe-west]
Services to deploy:
descriptor: [/Users/realpython/Documents/helloapp/]
source: [/Users/realpython/Documents/helloapp]
target project: [hello-app-295110]
target service: [default]
target version: [20201109t112408]
target url: [
Do you want to continue (Y/n)?
After you confirm the setup by typing Y, your deployment will finally be on its way. Your terminal will show you some more information and a small loading animation while Google App Engine sets up your project on its servers:
Beginning deployment of service [default]…
Created. gcloudignore file. See `gcloud topic gcloudignore` for details.
╠═ Uploading 3 files to Google Cloud Storage ═╣
File upload done.
Updating service [default]… ⠼
Since this is the first deployment of your web app, it may take a few minutes to complete. Once the deployment is finished, you’ll see another helpful output in the console. It’ll look similar to the one below:
Deployed service [default] to [
You can stream logs from the command line by running:
$ gcloud app logs tail -s default
To view your application in the web browser run:
$ gcloud app browse
You can now navigate to the mentioned URL in your browser, or type the suggested command gcloud app browse to access your live web app. You should see the same short text response that you saw earlier when running the app on your localhost: Congratulations, it’s a web app!
Notice that this website has a URL that you can share with other people, and they’ll be able to access it. You now have a live Python web application!
Change the return value of index() again and deploy your app a second time using the gcloud app deploy command. Confirm that you can see the change reflected on the live website in your browser.
With this, you’ve completed the necessary steps to get your local Python code up on the web. However, the only functionality that you’ve put online so far is printing out a string of text.
Time to step it up! Following the same process, you’ll bring more interesting functionality online in the next section. You’ll refactor the code of a local temperature converter script into a Flask web app.
Convert a Script Into a Web Application
Since this tutorial is about creating and deploying Python web applications from code you already have, the Python code for the temperature converter script is provided for you here:
def fahrenheit_from(celsius):
“””Convert Celsius to Fahrenheit degrees. “””
fahrenheit = float(celsius) * 9 / 5 + 32
fahrenheit = round(fahrenheit, 3) # Round to three decimal places
return str(fahrenheit)
except ValueError:
return “invalid input”
celsius = input(“Celsius: “)
print(“Fahrenheit:”, fahrenheit_from(celsius))
This is a short script that allows a user to convert a Celsius temperature to the equivalent Fahrenheit temperature.
Save the code as a Python script and give it a spin. Make sure that it works as expected and that you understand what it does. Feel free to improve the code.
With this working script in hand, you’ll now need to change the code to integrate it into your Flask app. There are two main points to consider for doing that:
Execution: How will the web app know when to run the code?
User input: How will the web app collect user input?
You already learned how to tell Flask to execute a specific piece of code by adding the code to a function that you assign a route to. Start by tackling this task first.
Add Code as a Function
Flask separates different tasks into different functions that are each assigned a route through the decorator. When the user visits the specified route via its URL, the code inside the corresponding function gets executed.
Start by adding fahrenheit_from() to your file and wrapping it with the decorator:
from flask import Flask
app = Flask(__name__)
def index():
return “Congratulations, it’s a web app! ”
So far, you’ve only copied the code of your Python script into a function in your Flask app and added the decorator.
However, there’s already a problem with this setup. What happens when you run the code in your development server? Give it a try.
Currently, both of your functions are triggered by the same route (“/”). When a user visits that route, Flask picks the first function that matches it and executes that code. In your case, this means that fahrenheit_from() never gets executed because index() matches the same route and gets called first.
Your second function will need its own unique route to be accessible. Additionally, you still need to allow your users to provide input to your function.
Pass Values to Your Code
You can solve both of these tasks by telling Flask to treat any remaining part of the URL following the base URL as a value and pass it on to your function. This requires only a small change to the parameter of the decorator before fahrenheit_from():
# — snip —
The angle bracket syntax (<>) tells Flask to capture any text following the base URL (“/”) and pass it on to the function the decorator wraps as the variable celsius. Note that fahrenheit_from() requires celsius as an input.
Head back to your web browser and try out the new functionality using Flask’s development server. You’re now able to access both of your functions through your web app using different URL endpoints:
Index (/): If you go to the base URL, then you’ll see the short encouraging message from before.
Celsius (/42): If you add a number after the forward slash, then you’ll see the converted temperature appear in your browser.
Play around with it some more and try entering different inputs. Even the error handling from your script is still functional and displays a message when a user enters a nonnumeric input. Your web app handles the same functionality as your Python script did locally, only now you can deploy it to the Internet.
Refactor Your Code
Flask is a mature web framework that allows you to hand over a lot of tasks to its internals. For example, you can let Flask take care of type checking the input to your function and returning an error message if it doesn’t fit. All this can be done with a concise syntax inside of the parameter to Add the following to your path capturer:
Adding int: before the variable name tells Flask to check whether the input it receives from the URL can be converted to an integer. If it can, then the content is passed on to fahrenheit_from(). If it can’t, then Flask displays a Not Found error page.
After applying Flask’s type check, you can now safely remove the try … except block in fahrenheit_from(). Only integers will ever be passed on to the function by Flask:
With thi

Frequently Asked Questions about python web examples

Can you create a website with Python?

Python can be used to build server-side web applications. … However, most Python developers write their web applications using a combination of Python and JavaScript. Python is executed on the server side while JavaScript is downloaded to the client and run by the web browser.

How do I make a simple Python website?

The language of Python is extremely powerful and very advanced for web design and development. Developers with this skill are in great demand, but it is difficult to find a high-quality web development company that uses Python for web development.

Is Python good for Web applications?

Another popular website using Python is Google. The language and its complementary framework allow developers to switch the traffic and handle the search requirements for each and every level. Google is a Python web application that runs seamlessly without many issues in the development process.Feb 8, 2021

Leave a Reply

Your email address will not be published. Required fields are marked *