Loading video player…

Brush Up on the Basics

00:00 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 video course: what types of Python code distribution exist, what a web application is, why building a web application can be a good choice, how content gets delivered over the Internet, what web hosting means, and which hosting providers exist, and which one to use.

00:29 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.

00:43 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, a standalone program, and a Python web application.

00:59 You’ll take a closer look at each of these approaches next. If you’ve worked with Python’s extensive package ecosystem, then you’ve likely installed Python packages using 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 themselves.

01:20 After you successfully publish your code to PyPI, this command will install your package, including its dependencies, on any of your users’ computers, providing they have an Internet connection.

01:31 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.

01:57 Many people who will 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.

02:08 A more user-friendly way to present your code to potential users is to build a standalone program. Computer programs come in different shapes and forms, and there are multiple options for transforming your Python scripts into standalone programs. Next, you will see two possibilities: packaging your code and building a graphical user interface.

02:29 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.

02:47 To learn more about packaging your code, check out Using PyInstaller to Easily Distribute Python Applications, or you can listen to the Real Python Podcast episode Options for Packaging Your Python Application.

03:02 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, commonly abbreviated to GUI.

03:15 You can make your Python code accessible to more people by building a GUI for it. There are different packages that can help you with building a GUI, including Tkinter, wxPython, and PySimpleGUI.

03:29 If you want to build a native desktop-based app, then check out the learning path for Python GUI Programming.

03:37 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.

03:49 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.

03:59 Because of these barriers to entry, it makes sense that many developers build web applications instead. These can be accessed on a browser which most systems will already have installed, and it makes your application truly cross-platform.

04:13 The advantage of web applications is that they are platform independent and can be run by anyone who has access to the Internet. The 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.

04:30 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 be using in this course. However, instead of this web-first approach, you’re going to take a different angle.

04:50 After all, you weren’t planning to build a web application. You just created a useful Python script, and now you want to share it 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.

05:04 It’s time to go over what a web application is and how it’s different from other content on the Web. Historically, websites had fixed content that was the same for every user who accessed that page.

05:17 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.

05:33 On-screen, you can see an example of a static website at the first URL that ever went online. And if you follow the link seen on-screen, you’ll also be able to see the pages that it links to.

05:44 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 change the content they deliver.

06:02 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. Importantly, it also shows your email to you and someone else’s email to them.

06:19 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.

06:32 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 earlier, you’ll build a basic Flask application in this course.

06:51 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.

Become a Member to join the conversation.