Daniel Chan
07/07/2025, 7:11 PMMarvin
07/07/2025, 7:11 PMDaniel Chan
07/07/2025, 7:12 PMMarvin
07/07/2025, 7:12 PMMarvin
07/07/2025, 7:12 PMpython
from prefect import flow
@flow
def my_flow():
print("Hello from my flow!")
# Deploy the flow
my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool",
# Optional: specify a schedule
schedule={"interval": "1h"},
# Optional: add tags
tags=["prod"]
)
2. Using prefect.yaml
Configuration:
Create a prefect.yaml
file in your project:
yaml
deployments:
- name: my-deployment
entrypoint: path/to/flow.py:my_flow
work_pool:
name: my-work-pool
schedule:
interval: 1h
tags:
- prod
Then deploy using the CLI:
bash
prefect deploy
For remote code (like GitHub), you can use:
python
from prefect import flow
from prefect.deployments import deploy
flow.from_source(
"<https://github.com/your-username/your-repo>",
entrypoint="path/to/flow.py:my_flow"
).deploy(
name="my-deployment",
work_pool_name="my-work-pool"
)
A few important notes:
- You'll need a work pool set up before deploying
- The deployment name must be unique within your workspace
- Make sure your code and dependencies are accessible to the worker that will run the flow
For more details, check out:
- Deployments Concept Documentation
- prefect.yaml Configuration Guide
- Work Pools and Workers Guide
Would you like me to elaborate on any particular aspect of the deployment process?Daniel Chan
07/07/2025, 7:13 PMMarvin
07/07/2025, 7:13 PMMarvin
07/07/2025, 7:13 PMpython
from prefect import flow
from prefect.client.orchestration import get_client
@flow
def my_flow():
print("Hello from my flow!")
# Deploy the flow
my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool"
)
2. Deployment from Source Control:
python
from prefect.flows import Flow
# Deploy from a GitHub repository
flow = Flow.from_source(
source="<https://github.com/username/repo>",
entrypoint="path/to/file.py:flow_function"
).deploy(
name="my-deployment",
work_pool_name="my-work-pool"
)
You can enhance your deployment with additional configurations:
python
my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool",
schedule={"interval": "1h"}, # Run every hour
tags=["prod"],
parameters={"key": "value"},
description="My production deployment"
)
Key deployment options include:
- `name`: The deployment name (required)
- `work_pool_name`: The work pool to run the deployment in
- `schedule`: Define when the flow should run
- `tags`: Add metadata tags
- `parameters`: Set default parameters
- `description`: Add a description
- `version`: Specify a version
- `triggers`: Configure event-based triggers
For more detailed information, you can refer to:
- Deployment via Python Guide
- Deployments Concept Documentation
Would you like me to elaborate on any specific aspect of the deployment process?Nate
07/07/2025, 7:14 PMNate
07/07/2025, 7:14 PMMarvin
07/07/2025, 7:14 PMpython
from prefect.client import get_client
from prefect.client.schemas.objects import AutomationCore, Trigger, RunDeployment
async def create_automation():
client = get_client()
# Define the automation
automation = AutomationCore(
name="My Automated Trigger",
description="Triggers when a deployment succeeds",
enabled=True,
triggers=[
Trigger(
match_related_deployment_id="your-deployment-id",
match_state_name="COMPLETED"
)
],
actions=[
RunDeployment(
deployment_id="target-deployment-id"
)
]
)
# Create the automation
await client.create_automation(automation)
Using the REST API:
python
import requests
def create_automation():
api_url = "<https://api.prefect.cloud/api/v1/automations>"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
automation_data = {
"name": "My Automated Trigger",
"description": "Triggers when a deployment succeeds",
"enabled": True,
"triggers": [{
"match_related_deployment_id": "your-deployment-id",
"match_state_name": "COMPLETED"
}],
"actions": [{
"type": "run-deployment",
"deployment_id": "target-deployment-id"
}]
}
response = <http://requests.post|requests.post>(api_url, json=automation_data, headers=headers)
return response.json()
You can find more details in:
- Creating Automations Guide
- Automations REST API Reference
The key components you'll need to specify are:
1. A name for the automation
2. The trigger conditions (what events will trigger the automation)
3. The actions to take when triggered
4. Whether the automation should be enabled immediately
Would you like me to provide more specific examples for certain types of triggers or actions?Nate
07/07/2025, 7:14 PMAutomation
object or triggers
kwarg in .serve
or .deploy
Daniel Chan
07/07/2025, 7:15 PMDaniel Chan
07/07/2025, 7:15 PMNate
07/07/2025, 7:15 PMNate
07/07/2025, 7:16 PMDaniel Chan
07/07/2025, 7:16 PMDaniel Chan
07/07/2025, 7:17 PMDaniel Chan
07/07/2025, 7:20 PMMarvin
07/07/2025, 7:20 PMMarvin
07/07/2025, 7:21 PMpython
from prefect.client import get_client
from prefect.client.schemas.objects import AutomationCore, Trigger, CancelFlowRun
async def create_timeout_automation():
client = get_client()
automation = AutomationCore(
name="Cancel Long-Running Flows",
description="Cancels flows running longer than 5 minutes",
enabled=True,
triggers=[
Trigger(
match_state_name="RUNNING",
match_state_duration_s=300 # 5 minutes in seconds
)
],
actions=[
CancelFlowRun()
]
)
await client.create_automation(automation)
Or using the REST API:
python
import requests
def create_timeout_automation():
api_url = "<https://api.prefect.cloud/api/v1/automations>"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
automation_data = {
"name": "Cancel Long-Running Flows",
"description": "Cancels flows running longer than 5 minutes",
"enabled": True,
"triggers": [{
"match_state_name": "RUNNING",
"match_state_duration_s": 300
}],
"actions": [{
"type": "cancel-flow-run"
}]
}
response = <http://requests.post|requests.post>(api_url, json=automation_data, headers=headers)
return response.json()
While it would be convenient to have YAML configuration support for automations (similar to how deployments work with prefect.yaml
), this functionality isn't currently available. If you need to create multiple automations or want to version control them, you might want to create a Python script that uses one of the above methods to set up your automations programmatically.
Would you like me to provide more details about specific trigger conditions or action types you can use with these methods?Nate
07/07/2025, 7:22 PMDaniel Chan
07/07/2025, 7:23 PMDeployment triggers are a special case of automations where the configured action is always running a deployment.But, I want my configuration action to be canceling a flow run?
Nate
07/07/2025, 7:26 PMRun Deployment
action, and you want a general automation, there is indeed a gap for yaml here
i think we should add this in the automations cli, like
prefect automation create foo.yaml # foo.json
so for now yeah marvin is right that you'd want the SDK or the REST api directlyDaniel Chan
07/07/2025, 7:27 PMNate
07/07/2025, 7:27 PMDaniel Chan
07/07/2025, 7:29 PMNate
07/07/2025, 7:30 PMDaniel Chan
07/07/2025, 7:33 PMNate
07/07/2025, 7:49 PMNate
07/07/2025, 7:49 PMDaniel Chan
07/07/2025, 7:58 PMNate
07/07/2025, 8:17 PMNate
07/07/2025, 8:17 PMDaniel Chan
07/07/2025, 8:31 PMDaniel Chan
07/07/2025, 8:38 PMNate
07/07/2025, 9:23 PM