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

# service.py
from flask import Flask

app = Flask(__name__)

@app.route("/health")
def health_check():
    return "OK"

# Service entrypoints receive the port from Datatailr.
def run_server(port):
    app.run("0.0.0.0", port=int(port), debug=False)

svc = Service(
    name="Simple Service",
    entrypoint=run_server,
    python_requirements=["flask"],
)
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=None, 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 Optional[Dict[str, str | int | float | bool]]

Environment variables passed to the running container.

None
update_existing bool

If True, update an existing job definition.

False