Hey all I’m trying to better understand how the Py...
# prefect-cloud
d
Hey all I’m trying to better understand how the Python SDK works. This script works on my local machine:
Copy code
import asyncio

from prefect import get_client
from prefect.flow_runs import wait_for_flow_run

async def main():
    async with get_client() as client:
        flow_run = await client.create_flow_run_from_deployment(deployment_id="<DEPLOYMENT_ID>")
        print("create flow run")
        flow_run = await wait_for_flow_run(flow_run_id=flow_run.id)
        print(flow_run.state)

if __name__ == "__main__":
    asyncio.run(main())
I don’t understand how it is connecting to prefect cloud though? I don’t have any environment variables set. How would I enable this script to authenticate with my prefect cloud account on any machine e.g. in a cloud VM ? Could someone please explain how the python SDK authenticates to my prefect cloud environment
1
d
tl;dr
prefect cloud login
stores a config file on the machine it's running on that contains your api key. By default this file is at
~/.prefect/profiles.toml
d
Ahh ok cool thank you. I have created a google cloud function script that triggers
create_flow_run_from_deployment
function using the API and python requests library. How would one authenticate using
prefect cloud login
in order to use the python SDK in a google cloud function?
d
You can configure prefect settings with environment variables
I believe api key is
PREFECT_API_KEY
but let me double check
So for a Google Cloud Function you'd configure a secret in secret manager that's injected into the function via environment variable. Prefect will pick up the variable and run against Prefect Cloud with the key configured automatically
d
Ah ok great that makes sense. Thank you very much for your help 🙂
d
Of course! Happy Engineering 😄
🦜 1