Isaac
01/15/2025, 6:32 AMMarvin
01/15/2025, 6:33 AMdeploy
method on a flow. Here's a simple example based on the information I found:
1. Create a Deployment from Python Code:
- You can create a deployment from your flow code by calling the .deploy()
method on a flow.
2. Example Code:
python
from prefect import flow
@flow
def my_flow():
# Your flow logic here
pass
if __name__ == "__main__":
deployment = my_flow.deploy(name="my_deployment")
deployment.run() # This will execute the deployment
3. Additional Context:
- Ensure you have a prefect.yaml
file in your directory if you are managing configurations through YAML.
- You can also explore the deploy.py
script from this GitHub source for more complex deployment scenarios.
4. Documentation Links:
- Prefect Deployment Infrastructure Examples
- Prefect YAML Deployment Concepts
This should give you a basic understanding of how to execute a deployment programmatically using Prefect 3.x. If you have more specific requirements or configurations, you might need to adjust the code accordingly.Isaac
01/15/2025, 6:34 AMMarvin
01/15/2025, 6:34 AMpython
from prefect.client import get_client
async def run_deployment(deployment_name: str):
async with get_client() as client:
deployment = await client.read_deployment_by_name(deployment_name)
flow_run = await client.create_flow_run_from_deployment(deployment.id)
print(f"Flow run created with ID: {flow_run.id}")
if __name__ == "__main__":
import asyncio
asyncio.run(run_deployment("my-existing-deployment"))
3. Steps:
- Import the Client: Use get_client
to interact with the Prefect API.
- Read the Deployment: Retrieve the deployment by its name using read_deployment_by_name
.
- Create a Flow Run: Use create_flow_run_from_deployment
to trigger the deployment.
4. Documentation Links:
- Prefect Deployment Infrastructure Concepts
This approach allows you to execute a deployment that has already been configured and registered with Prefect. Adjust the deployment name in the code to match your specific deployment.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.
Powered by