ray.serve.get_replica_context#

ray.serve.get_replica_context() ReplicaContext[source]#

Returns the deployment and replica tag from within a replica at runtime.

A replica tag uniquely identifies a single replica for a Ray Serve deployment.

Raises:

RayServeException – if not called from within a Ray Serve deployment.

Example

from ray import serve
@serve.deployment
class MyDeployment:
    def __init__(self):
        # Prints "MyDeployment"
        print(serve.get_replica_context().deployment)

DeveloperAPI: This API may change across minor Ray releases.