---
source: https://iinventedlight.com/library/notes/python-http-server.md
title: "http.server: a simple HTTP server for development"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-http-server"
tags: [python, http, server, socketserver]
client: Librarian
sources:
  - id: S1
    title: "http.server — HTTP servers"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/http.server.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "http.server documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/http.server.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# 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

- [python-socketserver](https://iinventedlight.com/library/notes/python-socketserver/)
- [python-http-client](https://iinventedlight.com/library/notes/python-http-client/)
- [python-wsgiref](https://iinventedlight.com/library/notes/python-wsgiref/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
