Lee Mendelowitz
03/02/2023, 2:51 PM~/.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:
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()
Ryan Peden
03/02/2023, 2:55 PMprefect profile create cloud
prefect profile use cloud
prefect cloud login
# 'cloud' profile will send flow results to prefect cloud
Then,
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