Skip to main content

Service

cc.service

#

Decorator used to create a function service by wrapping its initializer.

Parameters

_func(Optional[Callable]): Service initializer function to be wrapped. This function should return a dict-like object containing initialized values to be used by the service's endpoints.

executor(CloudExecutor): A CloudExecutor instance that specifies compute resources assigned to this service.

name(str): Optional name for the function service. Defaults to the decorated function's name.

description(str): Optional description for the function service. Defaults to the decorated function's docstring.

auth(bool): Whether or not to require an authentication token for requests. Auth is required by default.

tags(Optional[list]): An optional list of tags to associate with the function service. Defaults to None.

compute_share(Optional): Fraction of resources to allocate to each replica of the function service. Defaults to 1, meaning a single replica that uses all assigned resources.

volume: Choice of cloud storage volume to attach. Defaults to None.

Return Type

FunctionService

Returns

An function service object with an endpoint decorator method for assigning HTTP routes.

Examples

import covalent_cloud as cc

ex = cc.CloudExecutor(env="my-basic-env", num_cpus=2, memory="4GB", time_limit="45 minutes")

@cc.service(executor=ex, name="Sample Service", auth=False, tags=["sample", "demo"])
def sample_service(x: int, y: int) -> int:
return {"total": x + y}

@sample_service.endpoint("/add")
def special_addition(total: int, z: int) -> int:
return total + z

@sample_service.endpoint("/mul")
def special_multiplication(total: int, z: int) -> int:
return total * z


# Deploy the function service to Covalent Cloud.
client = cc.deploy(sample_service)(x=6, y=7)

# [Optional] wait for active state:
client = cc.get_deployment(client, wait=True)

# [Optional] access custom endpoints:
print(client.add(z=1)) # 14
print(client.mul(z=-1)) # -13