<@ULVA73B9P> can I use Python to create Deployment...
# marvin-in-the-wild
o
@Marvin can I use Python to create Deployments instead of using YAML?
m
Yes, you can create Prefect deployments using Python instead of YAML. You can use the
Deployment.build_from_flow
method to create a deployment from a Python object. Here is an example:
Copy code
python
from my_project.flows import my_flow
from prefect.deployments import Deployment

deployment = Deployment.build_from_flow(
    flow=my_flow,
    name="example-deployment",
    version=1,
    work_queue_name="demo",
    work_pool_name="default-agent-pool",
)
deployment.apply()
For more detailed information and examples, you can refer to the Prefect documentation on creating deployment from a Python object.
n
🙅
👍 1
@Marvin no, thats deprecated. use
.deploy()
m
My apologies for the outdated information. Yes, you're correct, you should use the
deploy()
method for creating deployments with Prefect 2.x. Here's an updated example using the
deploy()
method:
Copy code
python
from prefect import flow

@flow
def my_flow():
    # your flow definition
    pass

my_flow.deploy(
    name="example-deployment",
    work_queue_name="example-work-queue"
)
Please, make sure to replace
my_flow
with your actual flow function and customize the deployment details as necessary. For the latest usage and updates, always refer to the Prefect documentation.