Ops
The foundational unit of computation in Dagster.
Defining ops
- @dagster.op
Create an op with the specified parameters from the decorated function.
Ins and outs will be inferred from the type signature of the decorated function if not explicitly provided.
The decorated function will be used as the op’s compute function. The signature of the decorated function is more flexible than that of the
compute_fn
in the core API; it may:- Return a value. This value will be wrapped in an
Output
and yielded by the compute function. - Return an
Output
. This output will be yielded by the compute function. - Yield
Output
or other event objectsevent objects
. Same as default compute behavior. Note that options 1) and 2) are incompatible with yielding other events – if you would like to decorate a function that yields events, it must also wrap its eventual output in anOutput
and yield it.
@op supports
async def
functions as well, including async generators when yielding multiple events or outputs. Note that async ops will generally be run on their own unless using a customExecutor
implementation that supports running them together.Parameters:
- name (Optional[str]) – Name of op. Must be unique within any
GraphDefinition
- description (Optional[str]) – Human-readable description of this op. If not provided, and
- ins (Optional[Dict[str, In]]) – Information about the inputs to the op. Information provided here will be combined
- out (Optional[Union[Out, Dict[str, Out]]]) – Information about the op outputs. Information provided here will be combined with
- config_schema (Optional[ConfigSchema) – The schema for the config. If set, Dagster will check
- required_resource_keys (Optional[Set[str]]) – Set of resource handles required by this op.
- tags (Optional[Dict[str, Any]]) – Arbitrary metadata for the op. Frameworks may
- code_version (Optional[str]) – (Experimental) Version of the logic encapsulated by the op. If set,
- retry_policy (Optional[RetryPolicy]) – The retry policy for this op.
Examples:
@op
def hello_world():
print('hello')
@op
def echo(msg: str) -> str:
return msg
@op(
ins={'msg': In(str)},
out=Out(str)
)
def echo_2(msg): # same as above
return msg
@op(
out={'word': Out(), 'num': Out()}
)
def multi_out() -> Tuple[str, int]:
return 'cool', 4- Return a value. This value will be wrapped in an
- class dagster.OpDefinition
Defines an op, the functional unit of user-defined computation.
End users should prefer the
@op
decorator. OpDefinition is generally intended to be used by framework authors or for programatically generated ops.Parameters:
-
name (str) – Name of the op. Must be unique within any
GraphDefinition
or -
input_defs (List[InputDefinition]) – Inputs of the op.
-
compute_fn (Callable) –
The core of the op, the function that performs the actual computation. The signature of this function is determined by
input_defs
, and optionally, an injected first argument,context
, a collection of information provided by the system. -
output_defs (List[OutputDefinition]) – Outputs of the op.
-
config_schema (Optional[ConfigSchema) – The schema for the config. If set, Dagster will check
-
description (Optional[str]) – Human-readable description of the op.
-
tags (Optional[Dict[str, Any]]) – Arbitrary metadata for the op. Frameworks may
-
required_resource_keys (Optional[Set[str]]) – Set of resources handles required by this op.
-
code_version (Optional[str]) – (Experimental) Version of the code encapsulated by the op. If set,
-
retry_policy (Optional[RetryPolicy]) – The retry policy for this op.
-
pool (Optional[str]) – A string that identifies the pool that governs this op’s execution.
Examples:
def _add_one(_context, inputs):
yield Output(inputs["num"] + 1)
OpDefinition(
name="add_one",
ins={"num": In(int)},
outs={"result": Out(int)},
compute_fn=_add_one,
)- alias
Creates a copy of this op with the given name.
- tag
Creates a copy of this op with the given tags.
- with_hooks
Creates a copy of this op with the given hook definitions.
- with_retry_policy
Creates a copy of this op with the given retry policy.
- property config_schema
The config schema for this op.
Type: IDefinitionConfigSchema
- property ins
A mapping from input name to the In object that represents that input.
Type: Mapping[str, In]
- property name
The name of this op.
Type: str
- property outs
A mapping from output name to the Out object that represents that output.
Type: Mapping[str, Out]
- property required_resource_keys
A set of keys for resources that must be provided to this OpDefinition.
Type: AbstractSet[str]
- property retry_policy
The RetryPolicy for this op.
Type: Optional[RetryPolicy]
- property tags
The tags for this op.
Type: Mapping[str, str]
- property version
- deprecated
This API will be removed in version 2.0. Use
code_version
instead..Version of the code encapsulated by the op. If set, this is used as a default code version for all outputs.
Type: str
-