modal.web_server

Decorator that registers an HTTP web server inside the container.

This is similar to @asgi_app and @wsgi_app, but it allows you to expose a full HTTP server listening on a container port. This is useful for servers written in other languages like Rust, as well as integrating with non-ASGI frameworks like aiohttp and Tornado.

Usage:

The above example starts a simple file server, displaying the contents of the root directory. Here, requests to the web endpoint will go to external port 8000 on the container. The http.server module is included with Python, but you could run anything here.

Internally, the web server is transparently converted into a web endpoint by Modal, so it has the same serverless autoscaling behavior as other web endpoints.

For more info, see the guide on web endpoints.