Hi everyone and congratulation for shipping 3.0, i...
# ask-community
d
Hi everyone and congratulation for shipping 3.0, it looks amazing We're in the process of integrating it inside our stack and I'm trying to understand what is the best way to programmatically set the setting PREFECT_API_URL without using an environment variable. I started looking at the context and the settings but I couldn't find a good example on how I could set some values within our app. In our case we would like to configure prefect as part of the
lifespan
function in FastAPI. thks
n
hi @Damien i would generally recommend using an environment variable or similar for production, but if you need an escape hatch, there's
temporary_settings
Copy code
In [1]: from prefect.settings import temporary_settings, PREFECT_API_URL

In [2]: with temporary_settings(updates={PREFECT_API_URL: "<http://localhost:4200/api>"}):
   ...:     from prefect import flow
   ...:     @flow
   ...:     def f(): pass
   ...:     f()
   ...:
01:48:22.285 | INFO    | prefect.engine - Created flow run 'hot-kakapo' for flow 'f'
01:48:22.288 | INFO    | prefect.engine - View at <http://localhost:4200/runs/flow-run/><UUID>
01:48:22.355 | INFO    | Flow run 'hot-kakapo' - Finished in state Completed()

In [3]: !prefect config view
PREFECT_PROFILE='pong'
PREFECT_API_KEY='********' (from profile)
PREFECT_API_URL='<https://api.prefect.cloud/api/accounts/><UUID>/workspaces/<UUID> (from profile)
PREFECT_DEBUG_MODE='False' (from profile)
PREFECT_LOGGING_LEVEL='INFO' (from profile)
d
Thanks Nate, I'll give it a try is it possible to change the settings globally or does it has to be in a context manager ?
n
no problem! can you elaborate on what you're trying to do? env vars / patching usually cover most things im familiar with
a
Sorry for getting into the thread but Nate, how would you recommend to set prefect api url it in the production environment where I’d like to either instantiate a local prefect 3 server or connect to the server URL provided by the user if URL was provided (which can be a Prefect 3 cloud)?