Joe Blauer
01/21/2025, 9:02 PMMarvin
01/21/2025, 9:02 PMtags
context manager. Here's a basic example:
python
from prefect import flow, tags
@flow
def my_flow():
print("Flow is running with dynamic tags!")
if __name__ == "__main__":
dynamic_tag = "dynamic_tag_example"
with tags(dynamic_tag):
my_flow()
This code snippet demonstrates how to set a tag dynamically within the flow code. You can replace "dynamic_tag_example"
with any logic to determine your tag name. For more context, you can refer to this example on GitHub.Joe Blauer
01/21/2025, 9:03 PMKevin Grismore
01/21/2025, 9:04 PMfrom prefect import flow, get_client
from prefect.runtime import flow_run
def update_tags(tags: list[str]):
flow_run_id = flow_run.get_id()
with get_client(sync_client=True) as client:
client.update_flow_run(flow_run_id=flow_run_id, tags=tags)
@flow
def dynamic_tags_flow(thing: str):
update_tags(["tag", "another_tag"])
# additional logic
if __name__ == "__main__":
dynamic_tags_flow("hi")
Joe Blauer
01/21/2025, 9:08 PMShahid Khan
02/06/2025, 4:51 AMShahid Khan
02/06/2025, 7:31 PM