wptserve

raw JSON →
4.0.3 verified Sat May 09 auth: no python

wptserve is a Python web server designed for web browser testing, typically used within the web-platform-tests (WPT) framework. Version 4.0.3 is current. It provides a lightweight HTTP server with support for various protocols and features like piping, subdomains, and SSL. Releases are infrequent, tied to WPT updates.

pip install wptserve
error ImportError: cannot import name 'WebTestHttpd' from 'wptserve'
cause Attempting to import WebTestHttpd from top-level wptserve instead of wptserve.server.
fix
Use 'from wptserve.server import WebTestHttpd'.
error OSError: [Errno 98] Address already in use
cause Port specified is already in use by another process.
fix
Specify a different port or kill the process using the port.
error wptserve.handlers.InvalidPathException
cause The requested path does not exist or is outside the document root.
fix
Ensure the requested file exists within the doc_root directory.
breaking Python 2 support dropped in wptserve 4.0.0. Python 3.6+ required.
fix Upgrade to Python 3.6 or later.
breaking The 'wptserve' package on PyPI is unrelated to the 'wptserve' subpackage within wpt's tools/ serve module. Installing from PyPI gives a standalone server, not the WPT-integrated version.
fix If you need the WPT-integrated server, use WPT's repository directly (pip install web-platform-tests).
gotcha WebTestHttpd does not automatically resolve relative paths for doc_root; it must be an absolute path.
fix Use os.path.abspath() to convert relative paths.

Starts a simple HTTP server serving static files.

from wptserve.server import WebTestHttpd
import os

server = WebTestHttpd(
    host='localhost',
    port=8000,
    doc_root='/path/to/static/files',
    key_file=os.environ.get('SSL_KEY_FILE', ''),
    cert_file=os.environ.get('SSL_CERT_FILE', '')
)
server.start()
print(f"Server running at http://{server.host}:{server.port}")
input("Press Enter to stop...")
server.stop()