A static file server

Serves a directory over HTTP, like python -m http.server. Five lines of Python's standard library, compiled to a native binary, and the same file runs under python3.

Run it

terminal
$ 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 -
another terminal
$ curl localhost:9000/hello.txt
hello from seadash

With no arguments it serves the current directory on port 8000.

The program

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

More examples

kv_server.sd · kv_client.sd