Skip to content

Service

Represents a long-running background service deployment on Datatailr.

A service runs continuously (e.g., an API server, a message consumer, or any always-on process). It is restarted automatically if it exits.

Example
from datatailr import Service

def run_server():
    import uvicorn
    uvicorn.run("myapi:app", host="0.0.0.0", port=8000)

svc = Service(
    name="My API Service",
    entrypoint=run_server,
    python_requirements="fastapi,uvicorn",
)
svc.run()

__init__(name, entrypoint, environment=Environment.DEV, image=None, run_as=None, resources=Resources(), acl=None, python_version='3.12', python_requirements='', build_script_pre='', build_script_post='', env_vars={}, update_existing=False)

Initialize a Service deployment.

Parameters:

Name Type Description Default
name str

Display name for the service.

required
entrypoint Callable

The callable (function) that starts the service.

required
environment Optional[Environment]

Target environment for the deployment.

DEV
image Optional[Image]

Pre-configured container Image.

None
run_as Optional[Union[str, User]]

User or username to run the service as.

None
resources Resources

CPU and memory resources for the container.

Resources()
acl Optional[ACL]

Access control list.

None
python_version str

Python version for the container image.

'3.12'
python_requirements str | List[str]

Python dependencies (see Image).

''
build_script_pre str

Dockerfile commands to run before installing requirements.

''
build_script_post str

Dockerfile commands to run after installing requirements.

''
env_vars Dict[str, str | int | float | bool]

Environment variables passed to the running container.

{}
update_existing bool

If True, update an existing job definition.

False