cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

python task

seefoods
Contributor II

Hello Guys,

I have define asset bundle which have rule to run a python task. This task have some parameters, So how can i interract with this using argparse ? 

Cordially, 

1 ACCEPTED SOLUTION

Accepted Solutions

SP_6721
Contributor III

Hi @seefoods ,

In your asset bundle YAML, define the parameters using the named_parameters field, for example like this:

tasks:
  - task_key: python_task
    python_wheel_task:
      entry_point: main
      named_parameters:
        input_path: "/data/input"
        output_table: "results"
        debug_mode: "true"

Then, in your Python script, use argparse to read those parameters:

import argparse

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--input_path", required=True)
    parser.add_argument("--output_table", required=True)
    parser.add_argument("--debug_mode", default="false")
    args = parser.parse_args()

When the job runs, Databricks automatically passes the values as command-line arguments, and argparse picks them up in your script.

View solution in original post

1 REPLY 1

SP_6721
Contributor III

Hi @seefoods ,

In your asset bundle YAML, define the parameters using the named_parameters field, for example like this:

tasks:
  - task_key: python_task
    python_wheel_task:
      entry_point: main
      named_parameters:
        input_path: "/data/input"
        output_table: "results"
        debug_mode: "true"

Then, in your Python script, use argparse to read those parameters:

import argparse

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--input_path", required=True)
    parser.add_argument("--output_table", required=True)
    parser.add_argument("--debug_mode", default="false")
    args = parser.parse_args()

When the job runs, Databricks automatically passes the values as command-line arguments, and argparse picks them up in your script.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now