On prefect 2, what’s the best way to do a flow run...
# ask-community
l
On prefect 2, what’s the best way to do a flow run without tracking by Prefect Cloud? My
~/.prefect/profiles.toml
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:
Copy code
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

@flow
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]
        <http://logger.info|logger.info>(f"{k}: {v}")

# This run won't be tracked by Prefect Cloud
test_run()
1
r
One way is to create cloud and local profiles, something like:
Copy code
prefect profile create cloud
prefect profile use cloud
prefect cloud login
# 'cloud' profile will send flow results to prefect cloud
Then,
Copy code
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.
l
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.