Hi! I'm trying to use Deployment() to deploy my fl...
# prefect-community
Hi! I'm trying to use Deployment() to deploy my flow to an orion server. I'm not able to set the client right. Looks like Deployment().apply() is calling get_client() which gets the api_url from profile.toml. i want to set it from my script itself. How do I go about this?
Hi Jons. To build and apply a Deployment in Python code, check out this section of the docs. I think you want
Hi jeff, thank you for the response. But it doesnt look like build_from_flows supports client selection either..
Another issue im facing is: Im not able to create a deployment using
Copy code
flow = load_flows_from_script(path=str(path))
It throws
Copy code
File "/usr/local/lib/python3.9/site-packages/prefect/deployments.py", line 696, in build_from_flow
    module = importlib.import_module(mod_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named '__prefect_loader__'
It works fine if im importing the flow directly.
Also, Im trying to make one orion instance work for multiple environments. Is there any way i can tell a deployment to use certain blocks for the flows to pick up? I used to achieve similar behaviour in prefect 1.0 by separating flows based on projects and having different agents for different environments. I dont want to define which secret to be selected inside inside the flow itself.
Please let me know if you need me to create different threads for each of these.
any guidance would be really helpful.
Hi Jons. I don’t believe you can use blocks from different workspaces in the same deployment. The blocks are all stored server-side.
umm, thats not what im trying to do. All i want to do is set
pythonically before calling
Hi Jons. In your second code sample above, it looks like you are trying to use a client parameter when you load the S3 block, which isn’t an option. What are you trying to do?
is an environment variable for the client. You can just set it on the client directly from the CLI.
yes, PREFECT_API_URL is an environment var. i want to be able to set it without using env vars, thats all. in prefect 1 it was possible using
Copy code
from prefect.client.client import Client

client = Client(api_server="***")

build_and_register(client, flow, project_id, schedule=False)
(i prefer this since im multiple orion instances for our ci/cd)
looks like S3.load accepts a client option. please check the source
Copy code
Hi Jons. Looking at the source, I see what you’re saying. I’m not sure whether what you’re trying to do is possible, but the
decorator might be worth checking out. You can see the source code here. I’ll ask folks who are more familiar with that part of the code base than me if they have any insights tomorrow, Tuesday, when they are expected to be available and will report back. In the meantime, if you’d be so kind as to remove your message on this topic in the #prefect-community channel to keep it tidy, that would be great.
maybe I’m severely mis-interpreting here, but do you want this just a local scope (within the script) or as an env var afterwards? Could you just do something ala:
Copy code
import os
os.environ["PREFECT_API_URL"] = "<address>"
@Jeff Hale sure, removed my message. (didnt intend to put it there.)
🙏 1
@Christopher Boyd which is what im doing currently. but then i'll have to put all my prefect-imports locally scoped (because prefect loads the settings then i suppose).