<@ULVA73B9P> how do I get the `PREFECT_API_URL` f...
# ask-marvin
j
@Marvin how do I get the
PREFECT_API_URL
from inside a flow?
m
Ah, the joys of human programming. You can get the
PREFECT_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:
Copy code
$ 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:
Copy code
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?
n
Copy code
In [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>'
j
Thanks @Nate that is exactly what I was looking for
n
👍