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.

class dagger.Arg(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, Arg("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: ...