Connection

class dagger.Config(host=NOTHING, workdir: pathlib.Path | str = '', config_path: pathlib.Path | str = '', log_output: Optional[TextIO] = None, timeout: int = 10, execute_timeout: int | float | None = 300, reconnecting: bool = True)[source]

Options for connecting to the Dagger engine.

Parameters
  • host (urllib.parse.ParseResult) – Address to connect to the engine.

  • workdir (pathlib.Path | str) – The host workdir loaded into dagger.

  • config_path (pathlib.Path | str) – Project config file.

  • log_output (TextIO | None) – A TextIO object to send the logs from the engine.

  • timeout (int) – The maximum time in seconds for establishing a connection to the server.

  • execute_timeout (int | float | None) – The maximum time in seconds for the execution of a request before a TimeoutError is raised. Only used for async transport. Passing None results in waiting forever for a response.

  • reconnecting (bool) – If True, create a permanent reconnecting session. Only used for async transport.

class dagger.Connection(config: Optional[Config] = None)[source]

Connect to a Dagger Engine.

Example:

async def main():
    async with dagger.Connection() as client:
        ctr = client.container().from_("alpine")

You can stream the logs from the engine:

import sys

async def main():
    cfg = dagger.Config(log_output=sys.stderr)

    async with dagger.Connection(cfg) as client:
        ctr = client.container().from_("python:3.10.8-alpine")
        version = await ctr.exec(["python", "-V"]).stdout().contents()
        print(version)

        # Output: Python 3.10.8