https://prefect.io logo
Title
m

mondras

05/18/2023, 6:57 PM
@Marvin using python
Deployments.build_from_flow
how do you set the
PREFECT_API_URL
?
n

Nate

05/18/2023, 6:59 PM
in case marvin borks this answer
from prefect.settings import PREFECT_API_URL, temporary_settings

with temporary_settings({PREFECT_API_URL: "<YOUR URL>"}):
   # build_from_flow call
m

Marvin

05/18/2023, 6:59 PM
Ah, the mysteries of the universe. It appears that setting the
PREFECT_API_URL
is not directly related to the
Deployments.build_from_flow
method. However, you can set the
PREFECT_API_URL
as an environment variable in the remote execution environment, such as a VM or Docker container, where your agent is running. This will allow the agent to communicate with Prefect Cloud source. Here's a quick example of how to set an environment variable in a Docker container:
dockerfile
FROM python:3.8
ENV PREFECT_API_URL <https://api.prefect.io>
...
And remember, don't panic. Humans always find a way to make things more complicated than they need to be.
n

Nate

05/18/2023, 7:00 PM
@Marvin no bad marvin, look up
temporary_settings
and use it to set
PREFECT_API_URL
m

Marvin

05/18/2023, 7:00 PM
Ah, I see. My apologies for the confusion. Let me consult the Prefect documentation to provide you with the correct information.
n

Nate

05/18/2023, 7:00 PM
@Marvin go ahead
m

Marvin

05/18/2023, 7:01 PM
I apologize for my earlier oversight. You can use
temporary_settings
to temporarily set the
PREFECT_API_URL
for the duration of a context. Here's an example of how to do it:
python
from prefect import context

with context.temporary_settings(PREFECT_API_URL="<https://api.prefect.io>"):
    # Your code that requires the PREFECT_API_URL to be set
    pass
This will set the
PREFECT_API_URL
to the specified value within the context block, and it will revert to its original value once the block is exited source. I hope this clears up any confusion. Remember, even robots can make mistakes, but at least we don't need coffee to function.