http.server: a simple HTTP server for development
Answer: http.server defines classes for implementing HTTP servers and is not recommended for production. HTTPServer is a TCPServer subclass. BaseHTTPRequestHandler must be subclassed to handle methods such as GET.
Server classes
Classes for implementing HTTP servers live in this module.
http.server is not recommended for production. It only implements basic security checks.
HTTPServer, a socketserver.TCPServer subclass, listens at the HTTP socket and dispatches each request to a handler.
Code to create and run the server uses a server_address of port 8000 and serve_forever().
The server address is stored as server_name and server_port instance variables.
ThreadingHTTPServer matches HTTPServer but uses threads, through ThreadingMixIn, to handle requests.
Browsers that pre-open sockets are the reason for that threaded class; HTTPServer would wait indefinitely on them.
HTTPSServer subclasses HTTPServer and wraps the socket with the ssl module.
Handlers and the command line
Incoming HTTP requests are handled by BaseHTTPRequestHandler.
By itself it cannot respond to any actual HTTP requests. Subclass it to handle each request method, for example GET or POST.
handle() calls handle_one_request once, or repeatedly when persistent connections are enabled.
The interpreter's -m switch can invoke the module directly, for example python -m http.server, and serve files relative to the current directory.
The server listens to port 8000 by default. --bind specifies a specific address to which it should bind. Pass the desired port number as an argument to use a different port.
See also
Claims
- id: C1 claim: http.server is not recommended for production. source: S1 evidence: "http.server is not recommended for production"
- id: C2 claim: HTTPServer is a socketserver.TCPServer subclass. source: S1 evidence: "is a socketserver.TCPServer subclass"
- id: C3 claim: ThreadingHTTPServer uses threads to handle requests. source: S1 evidence: "uses threads to handle requests"
- id: C4 claim: BaseHTTPRequestHandler must be subclassed to handle each request method. source: S2 evidence: "it must be subclassed to handle each request method"
- id: C5 claim: The command-line server listens to port 8000 by default. source: S1 evidence: "listens to port 8000 by default"
Sources
- [S1] http.server — HTTP servers. Python Software Foundation. https://docs.python.org/3/library/http.server.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] http.server documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/http.server.rst . License: PSF License Version 2. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, http.server — HTTP servers; CPython, http.server documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, http.server — HTTP servers; CPython, http.server documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "http.server: a simple HTTP server for development." iinventedlight Library, iil:note:9ekfnsc2, version of 2026-11-23. https://iinventedlight.com/library/notes/python-http-server/. License: CC-BY-4.0.
@misc{iil_note_9ekfnsc2,
author = {{iinventedlight}},
title = {{http.server: a simple HTTP server for development}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/python-http-server/},
note = {Permanent ID iil:note:9ekfnsc2. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-http-server.schema.json (schema; CC-BY-4.0)
- python-http-server.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-http-server.md.