Module

Experimental Dagger modules support.

@dagger.object_type(cls: T | None = None) T | Callable[[T], T]

Exposes a Python class as a dagger.ObjectTypeDef.

Used with field() and function() to expose the object’s members.

Example usage:

@object_type
class Foo:
    @function
    def bar(self) -> str:
        return "foobar"
dagger.field(*, default: Callable[[], Any] | object = Ellipsis, name: str | None = None, init: bool = True) Any

Exposes an attribute as a dagger.FieldTypeDef.

Should be used in a class decorated with object_type().

Example usage:

@object_type
class Foo:
    bar: str = field(default="foobar")
    args: list[str] = field(default=list)
Parameters:
  • default – The default value for the field or a 0-argument callable to initialize a field’s value.

  • name – An alternative name for the API. Useful to avoid conflicts with reserved words.

  • init – Whether the field should be included in the constructor. Defaults to True.

@dagger.function(func: Callable[[P], R] | None = None, *, name: str | None = None, doc: str | None = None) Callable[[P], R] | Callable[[Callable[[P], R]], Callable[[P], R]]

Exposes a Python function as a dagger.Function.

Example usage:

@function
def foo() -> str:
    return "bar"
Parameters:
  • func – Should be a top-level function or instance method in a class decorated with object_type(). Can be an async function or a class, to use it’s constructor.

  • name – An alternative name for the API. Useful to avoid conflicts with reserved words.

  • doc – An alternative description for the API. Useful to use the docstring for other purposes.

@dagger.enum_type(cls: T | None = None) T | Callable[[T], T]

Exposes a Python enum.Enum as a dagger.EnumTypeDef.

The Dagger Python SDK looks for a description attribute in the enum member. There’s a convenience base class dagger.Enum that makes it easy to specify those descriptions as a second value.

Examples

Basic usage:

import enum
import dagger

@dagger.enum_type
class Options(enum.Enum):
    ONE = "ONE"
    TWO = "TWO"

Using convenience base class for descriptions:

import dagger


@dagger.enum_type
class Options(dagger.Enum):
    ONE = "ONE", "The first value"
    TWO = "TWO", "The second value"

Note

Only the values and their descriptions are reported to the Dagger API. The member’s name is only used in Python.

class dagger.DefaultPath(from_context: str)

Bases: object

If the argument is omitted, load it from the given path in the context directory.

Only applies to arguments of type dagger.Directory or dagger.File.

Mutually exclusive with setting a default value for the parameter. When used within Python, the parameter should be required.

Example usage:

@function
def build(src: Annotated[dagger.Directory, DefaultPath("..")]): ...
class dagger.Ignore(patterns: list[str])

Bases: object

Ignore patterns for dagger.Directory arguments.

The ignore patterns are applied to the input directory, and matching entries are filtered out, in a cache-efficient manner.

Useful if it’s known in advance which files or directories should be excluded when loading the directory.

Example usage:

@function
def build(src: Annotated[dagger.Directory, Ignore([".venv"])]): ...
class dagger.Enum(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

A string based enum.Enum with optional descriptions for the values.

Example usage:

class Options(dagger.Enum):
    ONE = "ONE", "The first value"
    TWO = "TWO"  # no description
class dagger.Name(name: str)

Bases: object

An alternative name when exposing a function argument to the API.

Useful to avoid conflicts with reserved words.

Example usage:

@function
def pull(from_: Annotated[str, Name("from")]): ...
class dagger.Doc(documentation: str, /)[source]

Bases: object

Define the documentation of a type annotation using Annotated, to be

used in class attributes, function and method parameters, return values, and variables.

The value should be a positional-only string literal to allow static tools like editors and documentation generators to use it.

This complements docstrings.

The string value passed is available in the attribute documentation.

Example:

>>> from typing_extensions import Annotated, Doc
>>> def hi(to: Annotated[str, Doc("Who to say hi to")]) -> None: ...