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
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
Daniel
06/05/2024, 2:40 PM
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
Dylan
06/05/2024, 2:50 PM
You can configure prefect settings with environment variables
Dylan
06/05/2024, 2:50 PM
I believe api key is
PREFECT_API_KEY
but let me double check
Dylan
06/05/2024, 2:51 PM
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
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.