httpserver
raw JSON → 1.1.0 verified Fri May 01 auth: no python
Asyncio implementation of an HTTP server. Version 1.1.0 provides a simple, async HTTP server built on asyncio. Release cadence is low; last release was 2023.
pip install httpserver Common errors
error ImportError: cannot import name 'HTTPServer' from 'httpserver' ↓
cause Incorrect import path; HTTPServer is a class in the httpserver module.
fix
Use 'from httpserver import HTTPServer'.
error TypeError: __init__() takes 1 positional argument but 3 were given ↓
cause Passing host and port as separate arguments to HTTPServer in version 1.1.0.
fix
Pass address as tuple: HTTPServer(('localhost', 8080), MyHandler).
error AttributeError: module 'httpserver' has no attribute 'server' ↓
cause Trying to import from a submodule that doesn't exist.
fix
Import directly from httpserver: from httpserver import HTTPServer.
Warnings
gotcha The server runs on the event loop; ensure your handler methods are not blocking or use async callbacks. ↓
fix Make handler methods async or offload blocking calls to executor.
deprecated The library is minimally maintained. For production, consider aiohttp or sanic. ↓
fix Evaluate if the library meets long-term needs.
breaking In version 1.1.0, the signature of HTTPServer changed: the first argument is now a tuple (host, port) instead of separate arguments. ↓
fix Change from HTTPServer('localhost', 8080, ...) to HTTPServer(('localhost', 8080), ...).
Imports
- HTTPServer wrong
import httpservercorrectfrom httpserver import HTTPServer - RequestHandler wrong
from httpserver.server import RequestHandlercorrectfrom httpserver import RequestHandler - get_handler
from httpserver import get_handler
Quickstart
import os
from httpserver import HTTPServer, RequestHandler
class HelloHandler(RequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b"Hello, world!")
server = HTTPServer(('localhost', 8080), HelloHandler)
print('Server running on http://localhost:8080')
server.serve_forever()