Connection
- class dagger.config.Config(workdir: PathLike[str] | str = '', config_path: PathLike[str] | str = '', log_output: TextIO | None = None, timeout: int = 10, execute_timeout: int | float | None = None)[source]
Options for connecting to the Dagger engine.
- Parameters:
workdir (os.PathLike[str] | str) – The host workdir loaded into dagger.
config_path (os.PathLike[str] | 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 an ExecuteTimeoutError is raised. Passing None results in waiting forever for a response (default).
- class dagger.connection.Connection(config: Config | None = 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 to see progress:
import sys import anyio import dagger async def main(): cfg = dagger.Config(log_output=sys.stderr) async with dagger.Connection(cfg) as client: ctr = client.container().from_("python:3.11.1-alpine") version = await ctr.with_exec(["python", "-V"]).stdout() print(version) # Output: Python 3.11.1 anyio.run(main)