David Beck
10/19/2022, 9:39 PMRyan Peden
10/19/2022, 10:04 PMDavid Beck
10/19/2022, 10:16 PMprefect.settings.<ENV_VAR>.value()
import prefect.settings
prefect.settings.PREFECT_API_KEY = "<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>"
Ryan Peden
10/19/2022, 10:34 PMimport os
import prefect
import prefect.settings
os.environ["PREFECT_API_KEY"] = "abc"
print(prefect.settings.PREFECT_API_KEY.value())
You get None
because prefect was loaded before the environment variable was set.
However, if you run:
import os
os.environ["PREFECT_API_KEY"] = "abc"
import prefect.settings
print(prefect.settings.PREFECT_API_KEY.value())
You get abc
because the environment variable was set before Prefect loaded.
Another option would be to have your CI/CD tooling set the environment variables before you run your Python script. Most CI/CD tools I've worked with make that easy, but I know some make it more difficult than others.David Beck
10/20/2022, 3:10 PM