All Products
Search
Document Center

Dataphin:Read files using Python

Last Updated:Jun 23, 2026

Use a Python script to read uploaded resource files such as .xlsx and .csv files. Install a third-party library such as openpyxl with pip for file parsing.

Prerequisites

Step 1: Upload a file

  1. In the top navigation bar of the Dataphin homepage, choose Lab > Data Development.

  2. In the navigation pane on the left, choose Data Processing > Resources. On the Resources page, click the image icon.

  3. In the Create resource dialog box, configure the parameters.

    image

    Parameter

    Description

    Type

    Select others.

    Name

    The file name must end with the file extension, for example, test.xlsx.

    Description

    Enter a description for the resource.

    Upload file

    Select a local file, such as test.xlsx.

    Compute type

    Select unassigned engine.

    Important

    Resource files are stored in the Dataphin system. Therefore, you can only select unassigned engine.

    Select directory

    The default value is Resource Management.

  4. Click Submit.

  5. In the Commit message dialog box, enter a message and click OK and Submit.

Step 2: Install a Python package

  1. In the top navigation bar of the Dataphin homepage, choose Management Center > System Settings.

  2. In the navigation pane on the left, choose Third-Party Library Management > Python Packages. On the Python Packages tab, click Install Python Package.

  3. In the Install Python package dialog box, configure the parameters.

    image

    Parameter

    Description

    Package name

    Enter the name of the Python package. For example, openpyxl.

    Package version

    Enter the package version. For example, 1.0.0.

    Python version

    Select Python 3.7.

    Installation method

    Select Online Installation.

  4. Click OK to install the package.

Step 3: Create a Python task

  1. In the navigation pane on the left, choose Data Processing > Compute Tasks.

  2. On the Compute Tasks page, click the image icon and select Python.

  3. In the New Python task dialog box, configure the parameters.

    image

    Parameter

    Description

    Task name

    Enter a name for the compute task, for example, Read_file_with_Python.

    Scheduling type

    Select Scheduled Task.

    Select directory

    The default value is Code Management.

    Use template

    This feature is disabled by default.

    Python version

    Select Python 3.7 or a later version.

    Python package

    Select the openpyxl package that you installed in Step 2.

    Description

    Enter a brief description for the task.

  4. Click OK to create the task.

Step 4: Write and run Python code

  1. On the code editing page, write the code. Replace test.xlsx with the name of your uploaded file.

    # -*- coding: utf-8 -*-
    
    import os
    import sys
    import openpyxl
    print ('========= python execute ok ==========')
    print("start===============")
    
    @resource_reference{"test.xlsx"}
    
    # Open the Excel file and get the sheet name.
    wb = openpyxl.load_workbook("test.xlsx")
    
    # The wb.get_sheet_names method is deprecated and will generate a warning.
    print(wb.worksheets[0])
  2. Click Run at the top of the page to run the task.

    A SUCCESS status indicates that the file was read successfully.test