https://prefect.io logo
#prefect-community
Title
# prefect-community
n

Nathaniel Russell

09/13/2022, 7:48 PM
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

Mason Menges

09/13/2022, 7:52 PM
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

Nathaniel Russell

09/13/2022, 8:00 PM
that shows how to do it with the command line but how do I do it in python?
m

Mason Menges

09/13/2022, 8:30 PM
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

Nathaniel Russell

09/13/2022, 8:46 PM
Thank you mason.
3 Views