https://prefect.io logo
Title
a

Adam

10/27/2022, 1:49 PM
Hi friends, I would like to make a common
create_deployment.py
utility that my CI/CD uses that will create and apply deployments when flows change. Instead of complicated bash, it’s easier to do it in Python. However, I’m unclear how I can get the
flow
object from a filepath in this case:
deployment = Deployment.build_from_flow(
    flow=my_flow, # how do i get from a filepath to the flow
    name="s3-example"
)
In Prefect v1, there was a useful utility called
from prefect.utilities.storage import extract_flow_from_file
— my question is does such a utility exist in v2? Or alternatively, is there a better way of doing this?
k

Kalise Richmond

10/27/2022, 4:01 PM
Hi Adam, you should just be able to import the flow from the file like in this example.
a

Adam

10/28/2022, 6:07 PM
Thanks, the specific question was about how to extract the
flow
object from a given filename i.e.
/User/adam/flows/myflow.py
. As we wanted to do something like
deploy.py --file=/Users/adam/myflow.py
which would be called by CI and then create the Deployment. Make more sense?
k

Kalise Richmond

10/28/2022, 9:51 PM
You should be able to send in the path as a kwarg to the deployments class. You typically want to use an absolute path. https://docs.prefect.io/api-ref/prefect/deployments/#prefect.deployments.Deployment