← All notes

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

Sources

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

Permanent ID: iil:note:9ekfnsc2

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.},
}

Markdown

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.

All artifact files (JSON index)

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.