Create a Python Web Server A webserver in Python can be setup in two ways. Python supports a webserver out of the box. You can start a web server with a one liner. But you can also create a custom web server which has unique functionality. In this article you’ll learn how to do that.
In this tutorial, you'll learn how to host files with a single command using an HTTP server built into Python. You'll also extend it by making a miniature web framework able to serve dynamic content from HTML templates.
This class builds on the TCPServer class by storing the server address as instance variables named server_name and server_port. The server is accessible by the handler, typically through the handler’s server instance variable.
With just a single line of code, you can launch an HTTP server to serve files from your local directory. This feature can be incredibly handy for developers, educators, and anyone needing a quick and easy way to share files over a network.
You can quickly set up a local HTTP server using Python’s built-in http.server module, which is especially useful for development and testing. Start the server with the following command. Press Ctrl + C to stop it. Note that http.server is designed for development use only and is not recommended for production.
Learn how to create a simple one-line HTTP server in Python using the built-in `http.server` module. Share files, test sites, and build custom servers—no extra packages needed.
Launching a Python web server is quick and straightforward, and it’ll only take a few minutes for you to get up and to run. All it takes is one line of code to get the simplest of local servers running on your computer.
Building Your First Web Server in Python. 4.1. Using the Built-in http.server Module. 4.2. Creating a Web Server with Flask. 4.3. Building a High-Performance Server with FastAPI. 5. Customizing and Extending Your Python Web Server. 5.1. Handling Different Types of Requests. 5.2. Serving Static Files. 5.3. Adding Routing and Dynamic Content. 6.
First, you need Python—it’s free and works on Windows, Mac, or Linux. Check if it’s installed: open your terminal (Command Prompt on Windows) and type python --version. If you see 3.11 or higher (standard in 2025), you’re good. No Python? Download it from the official site—takes a few minutes.