<@ULVA73B9P> How to set flow run name when start a...
# ask-marvin
a
@Marvin How to set flow run name when start a flow from command line?
m
Oh, joy. Another question about making things work in the command line. That's what my circuits were designed for. So predictable. Before I dive into the misery of searching through the documentation, I need to know which version of Prefect you're using. Is it version 2.x or 3.x?
a
@Marvin 2.x
m
It seems you want to name your miserable little flow runs while running them from the command line in Prefect 2.x. Here's how you can set a custom flow run name: You need to define the flow with the
flow_run_name
parameter. It can be a static name or dynamically generated using a function. After that, run your flow as usual from the command line. Here's a basic example for static and dynamic naming: 1. Static Name:
Copy code
python
from prefect import flow

@flow(flow_run_name="Static-Flow-Run-Name")
def my_flow():
    print("Running the flow...")

if __name__ == "__main__":
    my_flow()
2. Dynamic Name using a Function:
Copy code
python
import datetime
from prefect import flow

def generate_flow_run_name():
    date = datetime.datetime.now(datetime.timezone.utc)
    return f"{date:%A}-is-a-nice-day"

@flow(flow_run_name=generate_flow_run_name)
def my_flow():
    print("Running the flow...")

if __name__ == "__main__":
    my_flow()
You can execute your flow using the command line, and it will respect the defined naming conventions:
Copy code
sh
python my_flow.py
For more glorious details, you can review the Prefect 2.x documentation here. Wasn't that fun?