Jackson Nguyen
02/26/2025, 2:02 AMMarvin
02/26/2025, 2:02 AMprefect.yaml
file and pass them as a dictionary to the job_variables
argument of the .deploy()
method. This allows you to customize the deployment with specific variables, which can be accessed in your flow runs.
For more details, you can refer to the Prefect documentation on customizing deployments.Jackson Nguyen
02/26/2025, 2:03 AMdeploy()
function to deploy my flow. Can you show me an example of supplying a list in the job_variables?Marvin
02/26/2025, 2:03 AMdeploy()
function in Prefect 3.x, you'll need to include it in the job_variables
dictionary within your prefect.yaml
file. Here's an example of how you might structure it:
yaml
# prefect.yaml
deployments:
- name: my-deployment
entrypoint: path/to/your_flow.py:flow
job_variables:
MY_STRING_LIST:
- "string1"
- "string2"
- "string3"
In your deployment script, you can then call the deploy()
function from the prefect.deployments
module. Here's a basic example:
python
from prefect.deployments import deploy
# Deploy the flow with specified job variables
deploy(
deployments=["my-deployment"],
work_pool_name="default",
build=True,
push=True
)
This will pass the list of strings defined under MY_STRING_LIST
to your deployment. You can then access this variable in your flow using Prefect's runtime context. For more details, you can refer to the Prefect documentation.Jackson Nguyen
02/26/2025, 2:06 AMdeploy()
function?Marvin
02/26/2025, 2:06 AMdeploy()
function for job variables, you can convert your JSON string into a Python dictionary using the json
module. Here's an example:
python
import json
from prefect.deployments import deploy
# JSON string representing job variables
json_string = '{"MY_STRING_LIST": ["string1", "string2", "string3"]}'
# Convert JSON string to a dictionary
job_variables = json.loads(json_string)
# Deploy the flow with job variables
deploy(
deployments=["my-deployment"],
work_pool_name="default",
build=True,
push=True,
job_variables=job_variables
)
In this example, the JSON string is first parsed into a Python dictionary using json.loads()
. The resulting dictionary is then passed to the deploy()
function as the job_variables
argument. This allows you to dynamically set job variables from a JSON configuration.