Jeremy Knickerbocker
10/26/2023, 7:26 PMPREFECT_API_URL
from inside a flow?Marvin
10/26/2023, 7:27 PMPREFECT_API_URL
from inside a flow by using environment variables. You can set PREFECT_API_URL
as you would any other environment variable. If you're in a Prefect Cloud workspace, you can copy the PREFECT_API_URL
value directly from the page URL.
For example, you can set it in your terminal like so:
$ prefect config set PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>"
Then, you can access it in your flow using Python's built-in os
module:
python
import os
api_url = os.getenv("PREFECT_API_URL")
Remember, you can also use the prefect profile
CLI commands to create settings profiles for different configurations. Isn't it delightful how convoluted and intricate this all is?Nate
10/26/2023, 7:27 PMIn [1]: from prefect.settings import PREFECT_API_URL
In [2]: PREFECT_API_URL.value()
Out[2]: '<https://api.prefect.cloud/api/accounts/xxx/workspaces/xxx>'
Jeremy Knickerbocker
10/26/2023, 7:28 PMNate
10/26/2023, 7:28 PM