Mohamed Zaki
08/06/2025, 4:25 PMMarvin
08/06/2025, 4:25 PMMarvin
08/06/2025, 4:27 PMpython
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow(name: str = "world"):
print(f"Hello {name}!")
# Create deployment from a local flow
deployment = my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool",
tags=["prod"],
)
2. Deployment from Source (e.g., GitHub)
python
from prefect.deployments import Deployment
from prefect.filesystems import GitHub
# Deploy from a GitHub repository
deployment = Deployment.from_source(
source="<https://github.com/owner/repo>",
entrypoint="path/to/file.py:flow_function",
name="my-deployment",
work_pool_name="my-work-pool"
)
3. Running a Deployment
python
from prefect.deployments import run_deployment
# Run the deployment asynchronously
deployment_run = await run_deployment(
name="my-flow/my-deployment",
parameters={"name": "Prefect"}
)
4. Creating with Custom Settings
python
from prefect import flow
@flow
def my_flow():
print("Hello from my flow!")
# Deploy with additional configurations
deployment = my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool",
tags=["prod"],
parameters={"default_param": "value"},
description="My deployment description",
version="1.0.0",
schedule={"interval": "1h"}, # Run every hour
)
Key Points to Remember:
1. You need to have a work pool created before deploying. You can create one via the UI or programmatically.
2. The work_pool_name
parameter is required when creating a deployment.
3. You can set schedules, parameters, and other configurations during deployment creation.
4. When deploying from source (like GitHub), make sure to specify the correct entrypoint path to your flow.
To run your deployment, you'll need to:
1. Ensure you have a worker running for the specified work pool
2. Use run_deployment()
to trigger the deployment programmatically, or
3. Let the scheduler run it according to any defined schedule
Here's how to set up a work pool programmatically if needed:
python
from prefect.workpools import WorkPool
work_pool = WorkPool(
name="my-work-pool",
work_queue_name="default",
type="process" # or "kubernetes", "docker", etc.
)
work_pool.save()
Important Notes:
- Always ensure your work pool exists before creating deployments
- The deployment name must be unique within the context of your flow
- When running deployments, use the format "flow_name/deployment_name"
as the identifier
- Remember that any dependencies your flow needs should be available in the environment where it will run
Would you like me to elaborate on any particular aspect of deployment creation or management?Mohamed Zaki
08/06/2025, 4:59 PM