<@ULVA73B9P> In prefect.yaml there is the pull sec...
# ask-marvin
m
@Marvin In prefect.yaml there is the pull section. What is the equivalent in python when using deploy()
m
In Prefect 3.x, the
pull
section in the
prefect.yaml
file is used to define how your deployment is pulled in remote execution environments. When using the
deploy()
function in Python, you can configure this behavior programmatically. The
pull
section consists of a series of steps that are executed in sequence, each with optional fields like
requires
and
id
. These fields map directly to Python keyword arguments when using the
deploy()
function. To define this in Python, you would typically set up your deployment with the necessary steps in a similar sequence. Unfortunately, the exact Python equivalent isn't directly documented, but you can refer to the
deploy
function in the Prefect API to set up your deployment programmatically. For more details, you can review the Prefect 3.x documentation on deployment actions. If you have specific steps or configurations in mind, you might need to translate them into Python code that mimics the behavior of the steps in the
prefect.yaml
file.
n
.from_source
is the short answer
m
@Marvin @Nate But how would I add additional steps like e.g.
prefect.deployments.steps.set_working_directory
or
prefect.deployments.steps.pip_install_requirements
?
m
To add additional steps like
set_working_directory
or
pip_install_requirements
in your Python deployment script, you can use the functions provided in the
prefect.deployments.steps
module. Here's how you can incorporate these steps: 1. Set Working Directory: Use the
set_working_directory
function from the
prefect.deployments.steps.pull
module. 2. Pip Install Requirements: Use the
pip_install_requirements
function from the
prefect.deployments.steps.utility
module. Here's a basic example of how you might set these up in a Python script:
Copy code
python
from prefect.deployments.steps.pull import set_working_directory
from prefect.deployments.steps.utility import pip_install_requirements

# Set the working directory
set_working_directory('/path/to/working/directory')

# Install requirements
pip_install_requirements('/path/to/requirements.txt')
Ensure that you adjust the paths to match your specific requirements. These functions help in setting up your environment as part of the deployment process.
n
well you can always manually add
pull_steps
directly on the deployment object after you create it (not common), but essentially this is a tradeoff associated with using the python interface instead of yaml with the yaml its really easy to add arbitrary stuff like entire new steps like this (defined here)
m
I am currently using
prefect.yaml
with several steps. However I wonder whether I should migrate to python deployments instead. Main reason is that I plan to use `run_deployment()`in my flows. And by using python I can just define a constant for the deployment name. If the name is defined in
prefect.yaml
I need to duplicate the string.
n
you could use prefect variables, which you can template into your yaml and also read in python
m
Valid point. I'll consider that. Thanks a ton!
n
catjam