Get startedGet started for free

Create and run a Databricks job

In this exercise, you will create a job that runs a notebook with name HelloWorld that simply prints "Hello World". You can run whatever code that you want in the notebook referenced in the job.

This job needs to be explicitly told when to run.

The notebook path is dependent on the username of the authenticated user for the workspace and is structured as follows: /Users/${username}/${notebook_name}.

We have already created the WorkspaceClient(), storing as w.

This exercise is part of the course

Databricks with the Python SDK

View Course

Exercise instructions

  • Retrieve the username of the current user in the workspace to generate the notebook path for notebook with name HelloWorld.
  • Create a job that runs the HelloWorld notebook.
  • Run the job you just created.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Retrieve the notebook path of notebook in current user's workspace called 'HelloWorld'
notebook_path = f'/Users/{w.____.me().____}/HelloWorld'

# Create a job that runs the HelloWorld Notbeook
created_job = w.jobs.____(name='sdk-dc-project-task',
                          tasks=[
                              jobs.____(description="create_notebook_test",
                                        # Set the notebook_path
                                        notebook_task=jobs.NotebookTask(
                                            notebook_path=____),
                                        task_key="my-key")
                          ])

# Run job
w.jobs.____(created_job.____)
Edit and Run Code