how is ```prefect.client.get_client()``` supposed ...
# prefect-community
n
how is
Copy code
prefect.client.get_client()
supposed to know which account of prefect cloud to use? how does it get the api key?
1
m
Assuming you're referencing Prefect 2 you can specify it in the command but it will also pull it from the context of the prefect Profile you're currently using https://discourse.prefect.io/t/prefect-1-0-prefect-2-0-user-configurations-to-configuration-profiles/1299
n
that shows how to do it with the command line but how do I do it in python?
m
prefect.client.get_client()
is specifically looking for these 2 environment variables • PREFECT_API_URL • PREFECT_API_KEY As long as those are set whether you set them in you're python code or through the cli it'll return a client connected to Prefect Cloud based on those values, if they aren't set then it returns a client tied to an Ephemeral API. So something like this should work
Copy code
os.environ["PREFECT_API_URL"] = "<https://api.prefect.cloud/api/accounts/account_id/workspaces/workspace_id>"
os.envrion["PREFECT_API_KEY"] = "api_key"

prefect.client.get_client()
the profile serves as a base configuration in your environment but you can still set the variables manually which overwrites anything in the profile.
Basically you can configure those variables however you'd like, Profiles is a convenient way to store a consistent configuration but as long as those environment variables are set then regardless of how they're set it should function correctly
n
Thank you mason.