Modules
Dagger Modules support.
- @dagger.object_type(cls: T | None = None, *, deprecated: str | 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:
import dagger @dagger.object_type class Foo: @dagger.function def bar(self) -> str: return "foobar"
- Parameters:
deprecated – Optional deprecation message visible when introspecting the module.
- dagger.field(*, default: Callable[[], Any] | object = Ellipsis, name: str | None = None, init: bool = True, deprecated: str | None = None) 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.
deprecated – Optional deprecation message exposed to the engine.
- @dagger.function(func: Callable[[P], R] | None = None, *, name: str | None = None, doc: str | None = None, cache: str | None = None, deprecated: str | None = None) Callable[[P], R] | Callable[[Callable[[P], R]], Callable[[P], R]]
Exposes a Python function as a
dagger.Function.Example usage:
@object_type class Foo: @function def bar(self) -> str: return "foobar"
- Parameters:
func – Should be an 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.
deprecated – Optional deprecation message exposed to the engine.
- @dagger.enum_type
Exposes a Python
enum.Enumas adagger.EnumTypeDef.Example usage:
import enum import dagger @dagger.enum_type class Options(enum.Enum): """Enumeration description""" ONE = "ONE" """Description for the first value""" TWO = "TWO" """Description for the second value"""
- @dagger.interface
Exposes a Python class as a
dagger.InterfaceTypeDef.Used with
function()to expose the interface’s functions.Example usage:
import typing import dagger @dager.interface class Foo(typing.Protocol): @dagger.function async def bar(self) -> str: ...
- class dagger.DefaultPath(from_context: str)
Bases:
objectIf the argument is omitted, load it from the given path in the context directory.
Only applies to arguments of type
dagger.Directory/dagger.Fileordagger.GitRepository/dagger.GitRef.Mutually exclusive with setting a default value for the parameter. When used within Python, the parameter should be required.
Example usage:
@function def build(self, src: Annotated[dagger.Directory, DefaultPath("..")]): ... @function def build(self, src: Annotated[dagger.GitRef, DefaultPath("./.git")]): ...
- class dagger.Ignore(patterns: list[str])
Bases:
objectIgnore patterns for
dagger.Directoryarguments.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(self, src: Annotated[dagger.Directory, Ignore([".venv"])]): ...
- class dagger.Enum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
str,EnumA string based
enum.Enumwith optional descriptions for the values.Example usage:
class Options(dagger.Enum): ONE = "ONE", "The first value" TWO = "TWO" # no description
Deprecated
Use “enum.Enum” instead, with docstrings for descriptions.
- class dagger.Name(name: str)
Bases:
objectAn alternative name when exposing a function argument to the API.
Useful to avoid conflicts with reserved words.
Example usage:
@function def pull(self, 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: ...
- Define the documentation of a type annotation using