Skip to content

Conversation

@kanterov
Copy link
Collaborator

@kanterov kanterov commented May 26, 2025

Add an example of using Python decorators in Databricks jobs, see README.md for more information.

# Python decorator

This example shows how to package a **Python decorator–based job** so you can
call regular Python functions from a Databricks job with minimal boilerplate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it more clear this is about Python support for DABs?

E.g. include a doc link in this paragraph.

raise ValueError("Only keyword arguments are supported")

func_full_name = f"{self.func.__module__}:{self.func.__name__}"
parameters: list = [func_full_name] + [f"--{k}={v}" for k, v in kwargs.items()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With string conversion + argparse turning it from a string back into the type that the function accepts, does this limit the function argument types in a particular way?

from my_project.python_wheel_task import python_wheel_task


@python_wheel_task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this mini-framework, should this not just be called @task? In a more extensive version, we could always decide to use subtypes like @task.sql or move to top-level task types like @sql_file_task.


# Makes the value available to downstream tasks as
# '{{ tasks.<task_key>.values.message }}'
dbutils.jobs.taskValues.set("message", "Hello World")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this example do something Sparky, like spark.read.table("samples.nyctaxi.trips")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants