<@ULVA73B9P>: how to create deployments without se...
# marvin-in-the-wild
s
@Marvin: how to create deployments without serving them?
m
You want to deploy without deploying. Interesting concept! But let's dive deeper. Can you please specify which version of Prefect you're using? The method might vary between Prefect 2.x and 3.x.
s
I am using 3.x
@Marvin I am using 3.x
m
From the Prefect 3.x docs, it looks like calling
flow.to_deployment
alone actually does create the deployment object without registering it with the API. If you don't call
serve(...)
, the deployment won't be actively scheduled. Here's an example:
Copy code
python
import time
from prefect import flow, serve

@flow
def slow_flow(sleep: int = 60):
    "Sleepy flow - sleeps the provided amount of time (in seconds)."
    time.sleep(sleep)

@flow
def fast_flow():
    "Fastest flow this side of the Mississippi."
    return

if __name__ == "__main__":
    slow_deploy = slow_flow.to_deployment(name="sleeper", interval=45)
    fast_deploy = fast_flow.to_deployment(name="fast")
    # Serve is not called here, so deployments are created but not scheduled
    # serve(slow_deploy, fast_deploy)
By omitting the
serve(...)
call, you basically create deployments without serving them. For more detailed information, you can check the source documentation.
s
@Marvin I want to create the deployment and register with Prefect API as well but do not want the program to poll after that
m
To create and register a deployment with the Prefect API without starting a long-running process, you'll need to use a combination of the
to_deployment()
method and the Prefect CLI. 1. Use
to_deployment()
Method
: Create the deployment object using the
to_deployment()
method. 2. Register with the API Manually: Instead of serving it, use the Prefect CLI to register the deployment with the Prefect API. Here's a sample approach: 1. Define your flow and create the deployment object:
Copy code
python
from prefect import flow

@flow
def my_flow():
    print("Hello from my flow!")

deployment = my_flow.to_deployment(name="my-deployment")
2. Manually register the deployment using the Prefect CLI: After creating the deployment object, you can use the Prefect CLI to register it with the Prefect API. Save the deployment as a YAML file and then register it.
Copy code
bash
prefect deployment build -n my-deployment -p my_flow:deployment
prefect deployment apply my_flow-my-deployment.yaml
This way, you register the deployment with the Prefect API but do not start a long-running
serve
process. You can always refer to the official Prefect documentation for more details on running flows in local processes and deploying them. Would this solution work for you?