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()
andfunction()
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.