---
title: Use a Python wheel file in Lakeflow Jobs
description: Package Python code in a wheel file and run it as a Python wheel task in a Lakeflow Job, from building the wheel to running the job.
canonical_url: https://docs.databricks.com/aws/en/jobs/how-to/use-python-wheels-in-workflows
---

# Use a Python wheel file in Lakeflow Jobs

A Python [wheel file](https://peps.python.org/pep-0427/) is a standard way to package and distribute the files required to run a Python application. Using the Python wheel task, you can ensure fast and reliable installation of Python code in your jobs. This article provides an example of creating a Python wheel file and a job that runs the application packaged in the Python wheel file. In this example, you:

* Create the Python files defining an example application.
* Bundle the example files into a Python wheel file.
* Create a job to run the Python wheel file.
* Run the job and view the results.

## Prerequisites

You need the following to complete this example:

* Python3
* The Python `wheel` and `setuptools` packages. You can use `pip` to install these packages. For example, you can run the following command to install these packages:

  ```bash
  pip install wheel setuptools
  ```

## <a id="create-local-dir" />Step 1: Create a local directory for the example

Create a local directory to hold the example code and generated artifacts, for example, `databricks_wheel_test`.

## <a id="create-python-example" />Step 2: Create the example Python script

The following Python example is a simple script that reads input arguments and prints out those arguments. Copy this script and save it to a path called `my_test_code/__main__.py` in the directory you created in the previous step.

```python
"""
The entry point of the Python Wheel
"""

import sys

def main():
  # This method will print the provided arguments
  print('Hello from my func')
  print('Got arguments:')
  print(sys.argv)

if __name__ == '__main__':
  main()
```

## <a id="create-metadata" />Step 3: Create a metadata file for the package

The following file contains metadata describing the package. Save this to a path called `my_test_code/__init__.py` in the directory you created in step 1.

```python
__version__ = "0.0.1"
__author__ = "Databricks"
```

## <a id="create-wheel" />Step 4: Create the Python wheel file

Converting the Python artifacts into a Python wheel file requires specifying package metadata such as the package name and entry points. The following script defines this metadata.

> [!NOTE]
>
> The `entry_points` defined in this script are used to run the package in the Databricks workflow. In each value in `entry_points`, the value before `=` (in this example, `run`) is the name of the entry point and is used to configure the Python wheel task.

1. Save this script in a file named `setup.py` in the root of the directory you created in step 1:

   ```python
   from setuptools import setup, find_packages

   import my_test_code

   setup(
     name='my_test_package',
     version=my_test_code.__version__,
     author=my_test_code.__author__,
     url='https://databricks.com',
     author_email='john.doe@databricks.com',
     description='my test wheel',
     packages=find_packages(include=['my_test_code']),
     entry_points={
       'group_1': 'run=my_test_code.__main__:main'
     },
     install_requires=[
       'setuptools'
     ]
   )
   ```

2. Change into the directory you created in step 1, and run the following command to package your code into the Python wheel distribution:

   ```bash
   python3 setup.py bdist_wheel
   ```

This command creates the Python wheel file and saves it to the `dist/my_test_package-0.0.1-py3.none-any.whl` file in your directory.

## <a id="create-job" />Step 5. Create a job to run the Python wheel file

1. In your workspace, click ![Workflows icon.](https://docs.databricks.com/aws/en/images/product-icons/WorkflowsIcon.svg) **Jobs & Pipelines** in the sidebar.

2. Click **Create**, then **Job**.

3. Click the **Python wheel** tile to configure the first task. If the **Python wheel** tile is not available, click **Add another task type** and search for **Python wheel**.

4. Optionally, replace the name of the job, which defaults to **`New Job <date-time>`**, with your job name.

5. In **Task name**, enter a name for the task.

6. If necessary, select **Python wheel** from the **Type** drop-down menu.

7. In **Package name**, enter `my_test_package`. The **Package name** value is the name of the Python distribution, not the module you import. In this example, the package name is the value assigned to the `name` parameter in `setup.py`.

8. In **Entry point**, enter `run`. The entry point is one of the values specified in the `entry_points` collection in the `setup.py` script. In this example, `run` is the only entry point defined.

9. In **Compute**, select an existing job cluster or **Add new job cluster**.

10. Specify your Python wheel file:
    * In the **Environment and Libraries** drop-down, click the ![Pencil icon.](https://docs.databricks.com/aws/en/images/product-icons/PencilIcon.svg) next to **Default**, to edit it. Alternatively, click **Add new environment** to configure a new environment.
    * In the **Configure environment** dialog, click **Add dependency**.
    * Click ![Folder Icon](https://docs.databricks.com/aws/en/images/icons/folder.png) the folder icon to open the file browser. Drag and drop the wheel file that you created in step 4 into the **Select a dependency** dialog.
    * Click **Confirm**.

11. In **Parameters**, select **Positional arguments** or **Keyword arguments** to enter the key and the value of each parameter. Both positional and keyword arguments are passed to the Python wheel task as command-line arguments.
    * To enter positional arguments, enter parameters as a JSON-formatted array of strings, for example: `["first argument","first value","second argument","second value"]`.
    * To enter keyword arguments, click ![Plus icon.](https://docs.databricks.com/aws/en/images/product-icons/PlusIcon.svg) **Add** and enter a key and value. Click ![Plus icon.](https://docs.databricks.com/aws/en/images/product-icons/PlusIcon.svg) **Add** again to enter more arguments.

12. Click **Save task**.

## <a id="run-job" />Step 6: Run the job and view the job run details

Click ![Run Now Button](https://docs.databricks.com/aws/en/images/jobs/run-now-button.png) to run the workflow. To view [details for the run](https://docs.databricks.com/aws/en/jobs/monitor.md#job-run-details), click the **Runs** tab, then click the link in the **Start time** column for the run in the [job runs](https://docs.databricks.com/aws/en/jobs/monitor.md#view-job-run-list) view.

When the run completes, the output displays in the **Output** pane, including the arguments passed to the task.

## <a id="learn-more" />Next steps

To learn more about creating and running jobs, see [Lakeflow Jobs](https://docs.databricks.com/aws/en/jobs/index.md).
