Run it
$ sd run examples/serve.sd 9000 public
Serving HTTP on 0.0.0.0 port 9000 (http://0.0.0.0:9000/) ...
127.0.0.1 - - [01/Oct/2026 23:42:20] "GET /hello.txt HTTP/1.1" 200 -
$ curl localhost:9000/hello.txt
hello from seadash
With no arguments it serves the current directory on port 8000.
The program
# Serves a directory over HTTP, like `python -m http.server`.
#
# sd run examples/serve.sd # the current directory, on port 8000
# sd run examples/serve.sd 9000 # another port
# sd run examples/serve.sd 9000 public # another directory
#
# Each request is handled on a thread of its own (ThreadingHTTPServer), and
# SimpleHTTPRequestHandler gets its directory through functools.partial, as in Python.
# The same file runs under python3.
import sys
from functools import partial
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
directory = sys.argv[2] if len(sys.argv) > 2 else "."
with ThreadingHTTPServer(("", port), partial(SimpleHTTPRequestHandler, directory=directory)) as server:
print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...", flush=True)
server.serve_forever()
What to notice
http.serveris the real API.ThreadingHTTPServerandSimpleHTTPRequestHandlerfollow Python's, down to the log line format.functools.partialworks on classes. The handler class gets itsdirectorykeyword bound ahead of time, as in Python.- Threads are real. Each request runs on an OS thread of its own, in parallel; there's no GIL.
- Types without annotations.
portis inferred asintanddirectoryasstrfrom both branches of each conditional.