run#

ray.serve.run(target: Application, blocking: bool = False, name: str = 'default', route_prefix: str | None = '/', logging_config: Dict | LoggingConfig | None = None, _local_testing_mode: bool = False, external_scaler_enabled: bool = False, controller_options: None | dict | ControllerOptions = None) → DeploymentHandle[source]#

Run an application and return a handle to its ingress deployment.

The application is returned by Deployment.bind(). Example:

handle = serve.run(MyDeployment.bind())
ray.get(handle.remote())

serve.run deploys imperatively: it deploys an application object. Serve can’t tell which version of the code an application object holds, so every serve.run call redeploys the whole application, replacing all of its replicas, even when only a deployment option such as num_replicas changed. To update a running application in place, deploy it declaratively instead, from a config file with serve deploy or through the REST API: Serve then applies a lightweight config change, such as num_replicas, autoscaling_config or user_config, to the running replicas without restarting them. See Updating Applications In-Place.

Parameters:
  • target (Application) – A Serve application returned by Deployment.bind().

  • blocking (bool) – Whether this call should be blocking. If True, it will loop and log status until Ctrl-C’d.

  • name (str) – Application name. If not provided, this will be the only application running on the cluster (it will delete all others).

  • route_prefix (str | None) – Route prefix for HTTP requests. Defaults to ‘/’. If None is passed, the application will not be exposed over HTTP (this may be useful if you only want the application to be exposed via gRPC or a DeploymentHandle).

  • logging_config (Dict | LoggingConfig | None) – Application logging config. If provided, the config will be applied to all deployments which doesn’t have logging config.

  • _local_testing_mode (bool) – Internal flag for running the application in local-testing mode. Not part of the public contract.

  • external_scaler_enabled (bool) – Whether external autoscaling is enabled for this application.

  • controller_options (None | dict | ControllerOptions) – [EXPERIMENTAL] Options for the Serve controller actor (e.g. runtime_env.env_vars for HAProxy / controller-side tunables). See ray.serve.config.ControllerOptions. Only applied on first controller creation – ignored if a Serve controller is already running in this Ray cluster.

Returns:

A handle that can be used to call the application.

Return type:

DeploymentHandle