Jordan Jones
05/12/2026, 1:40 PMMarvin
05/12/2026, 1:40 PMMarvin
05/12/2026, 1:41 PMpython
import os
from prefect import flow
@flow
def my_flow():
worker_name = os.environ.get("PREFECT__WORKER_NAME")
print(f"Worker name: {worker_name}")
A few important notes:
- PREFECT__WORKER_NAME is set by the worker at execution time
- it will typically be None if the flow is not running under a Prefect worker
- there is not a standard prefect.runtime.flow_run.worker_name field for this
If you also want the worker ID:
python
import os
from prefect import flow
@flow
def my_flow():
print("Worker name:", os.environ.get("PREFECT__WORKER_NAME"))
print("Worker id:", os.environ.get("PREFECT__WORKER_ID"))
Related docs:
- Workers
- Runtime context
If you want, I can also show how to get this from inside a task or log it automatically for every run.