Skip to content

Instantly share code, notes, and snippets.

@noamtamim
Created March 28, 2025 13:43
Show Gist options
  • Save noamtamim/34c38666484fb8f8404f853736eaf2db to your computer and use it in GitHub Desktop.
Save noamtamim/34c38666484fb8f8404f853736eaf2db to your computer and use it in GitHub Desktop.
Smallest possible Python web server
# This server returns an empty JSON object, no matter what.
from wsgiref.simple_server import make_server
import threading
def start_server():
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'application/json')])
return [b'{}']
with make_server('', 8000, app) as httpd:
httpd.serve_forever()
# Option 1: just run. Control C to stop.
start_server()
# Option 2: start in a background thread (will exit with main thread).
threading.Thread(target=start_server, daemon=True).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment