Current - Operating a run
The current
object is used to inspect and manipulate the currently executing run. It is only available during flow execution, i.e. inside a FlowSpec
class and functions called from its steps. You can access the object simply by importing it: from metaflow import current
.
The attributes available in current
depend on the decorators assigned to the flow and the step where current
is used. Attributes that are always available are listed under Common Attributes below. Decorator-specific attributes are listed under the decorator name.
Common Attributes
These attributes are always available in the current
object.
Returns True if called inside a running Flow, False otherwise.
You can use this property e.g. inside a library to choose the desired behavior depending on the execution context.
bool
True if called inside a run, False otherwise.
The index of the task execution attempt.
This property returns 0 for the first attempt to execute the task. If the @retry decorator is used and the first attempt fails, this property returns the number of times the task was attempted prior to the current attempt.
int
The retry count.
The run ID of the original run this run was resumed from.
This property returns None for ordinary runs. If the run was started by the resume command, the property returns the ID of the original run.
You can use this property to detect if the run is resumed or not.
str, optional
Run ID of the original run.
Pathspec of the current task, i.e. a unique identifier of the current task. The returned string follows this format:
{flow_name}/{run_id}/{step_name}/{task_id}
This is a shorthand to current.task.pathspec
.
str, optional
Pathspec.
Decorator-specific attributes
These attributes are only available when the decorator is present.
@project
The @project decorator exposes attributes related to the current deployment.
The flow name prefixed with the current project and branch. This name identifies the deployment on a production scheduler.
str
Flow name prefixed with project information.
True if the flow is deployed without a
specific --branch
or a --production
flag.
bool
True if the deployment does not correspond to a specific branch.
True if the flow is deployed with the --production
flag.
bool
True if the flow is deployed in --production
.
@card
The @card decorator exposes functions in current
that allow you to customize
the contents of cards using card components. For an overview of card-related APIs, see the API reference for cards.
Choose a specific card for manipulation.
When multiple @card decorators are present, you can add an
ID
to distinguish between them, @card(id=ID)
. This allows you
to add components to a specific card like this:
current.card[ID].append(component)
key: str
Card ID.
CardComponentManager
An object with append
and extend
calls which allow you to
add components to the chosen card.
Specify components of the chosen card.
Instead of adding components to a card individually with current.card[ID].append(component)
,
use this method to assign a list of components to a card, replacing the existing components:
current.card[ID] = [FirstComponent, SecondComponent]
key: str
Card ID.
value: List[MetaflowCardComponent]
List of card components to assign to this card.
Appends a component to the current card.
component: MetaflowCardComponent
Card component to add to this card.
Appends many components to the current card.
component: Iterator[MetaflowCardComponent]
Card components to add to this card.
@trigger and @trigger_on_finish
You can inspect event(s) that triggered an event-triggered run through current.trigger
which returns a MetaflowTrigger
object, if the run was
triggered by an event.