artur
10/16/2024, 6:44 PMMarvin
10/16/2024, 6:44 PMprefect.runtime.get_tags()
and prefect.context.TagsContext()
based on the available documentation:
1. Prefect Runtime (prefect.runtime.get_tags()
):
- This is a part of the Prefect runtime tools that provides access to metadata and information about the current flow or task run.
- Although I couldn't find a direct reference to prefect.runtime.get_tags()
, the general use of runtime context like prefect.runtime
is to retrieve real-time information related to flows and tasks that are executing.
2. Prefect Context (prefect.context.TagsContext()
):
- prefect.context
is used to access contextual information during flow and task runs. It provides the execution context for tasks and flows.
- The runtime API context allows access to attributes related to the current run, and using functions like prefect.context.get_run_context()
provides direct access to the run context.
- TagsContext()
isn't directly mentioned either, but it could be a pattern to create or manage tags within the context. Prefect often uses contexts to encapsulate settings and states that are active during a run.
The functionalities of these methods might have evolved between different Prefect versions (2.x and 3.x), but the documentation I accessed didn't give specifics on these exact methods. It's possible these functions or classes are used internally or have recently been introduced.
For additional details, you might want to check the Prefect runtime context documentation for Prefect 2.x and Prefect 3.x.Nate
10/16/2024, 6:50 PMTagsContext
is an implementation detail that you wont find in the docsartur
10/16/2024, 7:07 PMfrom prefect.runtime import flow_run
from prefect.context import TagsContext
assert flow_run.get_tags() == TagsContext.get().current_tags
Nate
10/16/2024, 7:08 PMTagsContext
directly, because when you do, you're not necessarily talking about the tags context that the flow run is usingNate
10/16/2024, 7:08 PMartur
10/16/2024, 7:10 PMartur
10/16/2024, 7:12 PMNate
10/16/2024, 7:17 PMIn [1]: from prefect.context import get_run_context
In [2]: from prefect import task
In [3]: @task(tags={"a", "b", "c"})
...: def t():
...: print(get_run_context().task_run.tags)
...:
In [4]: t()
['a', 'b', 'c']
this is how I would access the tags for a current flow/taskartur
10/16/2024, 7:20 PMNate
10/16/2024, 7:22 PMruntime
and get_run_context
are both "public" interfaces and more or less providing access to the same things
runtime
is just convenient for stuff like task_run_name
or result_storage_key
so you can template extra stuff into those things