modal.Server
class Server(object)Server runs an HTTP server started in an @modal.enter method.
See lifecycle hooks for more information.
Generally, you will not construct a Server directly.
Instead, use the @app._experimental_server() decorator.
@app._experimental_server(port=8000, proxy_regions=["us-east", "us-west"])
class MyServer:
@modal.enter()
def start_server(self):
self.process = subprocess.Popen(["python3", "-m", "http.server", "8080"])get_urls
@live_method
def get_urls(self) -> Optional[dict[str, str]]:update_autoscaler
@live_method
def update_autoscaler(
self,
*,
min_containers: Optional[int] = None,
max_containers: Optional[int] = None,
buffer_containers: Optional[int] = None,
scaledown_window: Optional[int] = None,
) -> None:Override the current autoscaler behavior for this Server.
Unspecified parameters will retain their current value.
Examples:
server = modal.Server.from_name("my-app", "Server")
# Always have at least 2 containers running, with an extra buffer of 2 containers
server.update_autoscaler(min_containers=2, buffer_containers=1)
# Limit this Server to avoid spinning up more than 5 containers
server.update_autoscaler(max_containers=5)hydrate
def hydrate(self, client: Optional[_Client] = None) -> "_Server":
# This is required since we want to support @livemethod() decorated methodsfrom_name
@classmethod
def from_name(
cls: type["_Server"],
app_name: str,
name: str,
*,
environment_name: Optional[str] = None,
client: Optional[_Client] = None,
) -> "_Server":Reference a Server from a deployed App by its name.
This is a lazy method that defers hydrating the local object with metadata from Modal servers until the first time it is actually used.
server = modal.Server.from_name("other-app", "Server")