Lee Mendelowitz

03/02/2023, 2:51 PM
On prefect 2, what’s the best way to do a flow run without tracking by Prefect Cloud? My
is configured to connect to Prefect Cloud, but sometimes I just want to run flows locally without cloud tracking. I was able to figure something out with environment variables, but it seems hacky:
import os

# To disable tracking by Prefect UI, set these environment variables to empty values.
os.environ['PREFECT_API_URL'] = ''
os.environ['PREFECT_API_KEY'] = ''
os.environ['PREFECT_PROFILES_PATH'] = 'dont' # set to a path that doesn't exist

import prefect
import prefect.settings

from prefect import flow, get_run_logger

def test_run():
    logger = get_run_logger()
    st = prefect.settings.get_current_settings().dict()
    keys = sorted(st.keys())
    for k in keys:
        v = st[k]
        <|>(f"{k}: {v}")

# This run won't be tracked by Prefect Cloud

Ryan Peden

03/02/2023, 2:55 PM
One way is to create cloud and local profiles, something like:
prefect profile create cloud
prefect profile use cloud
prefect cloud login
# 'cloud' profile will send flow results to prefect cloud
prefect profile create local
prefect profile use local
# 'local' profile will not send results to cloud
And you can use
prefect profile use
to switch between them as needed.

Lee Mendelowitz

03/02/2023, 3:29 PM
Thanks @Ryan Peden good idea. I have a local profile already to connect to a local prefect orion server, so I just made an empty “none” profile with no PREFECT_API_URL set, and that seems to have done the trick.