Since there's no dead simple examples:
#!/usr/bin/env python
from wsgiref.handlers import CGIHandler
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return [
b"<html><head><title>foo</title></head><body>bar</body></html>\n"
]
if __name__ == '__main__':
CGIHandler().run(app)
Most of the examples show spinning up and listening to a port, but you can google around to find examples that work with just stdin/stdout.