All Products
Search
Document Center

MaxCompute:Develop a Python UDF

Last Updated:Mar 26, 2026

MaxCompute Studio lets you develop, test, and publish Python user-defined functions (UDFs) without leaving your IDE.

Prerequisites

Before you begin, ensure that you have:

Develop a Python UDF

  1. In the Project section, right-click scripts under the MaxCompute script module and choose New > MaxCompute Python.

  2. In the Create new MaxCompute python class dialog box, enter a class name in the Name field, select python UDF from the Kind drop-down list, and then click OK.

  3. Write the UDF code in the code editor.

Test the Python UDF

MaxCompute Studio supports local runs, which let you download sample data from a table to your local machine, run the UDF on that data, and debug the output.

  1. Right-click the developed Python UDF and select RUN.

  2. In the Edit configuration dialog box, configure the following parameters and click OK.

    **

    ParameterDescription
    MaxCompute projectThe MaxCompute project in which the UDF runs. Defaults to the connected project. To use a different project, add it as prompted.
    MaxCompute tableThe table whose data the UDF processes. Select a table from the drop-down list.
    Table columnsThe columns in the selected table that the UDF operates on.
    Download Record limitThe maximum number of records to download as sample data. Default: 100. To download more than 100 records, run the Tunnel command on the MaxCompute client, or use the table download feature in MaxCompute Studio.
    If the specified data is already downloaded, MaxCompute Studio skips the download. To re-download, run the Tunnel command on the MaxCompute client.
  3. MaxCompute Studio fetches the sample data based on the columns you specified and runs the UDF locally on that data. Local runs use the pyou script provided by PyODPS (the MaxCompute SDK for Python). The local run command takes the form pyou hello.Plus<data. After installing PyODPS, verify that the pyou script is available at the following path:

    OSPath
    Windows${python}/../Scripts/pyou
    macOS${python}/../pyou

    After the download, view the sample data in the data file of the table under the warehouse directory.

  4. View the output on the Console tab and debug the code if needed.

Publish the Python UDF

After testing, publish the UDF to the production environment. For more information, see Upload a Python program and create a MaxCompute UDF.