Preparations
Before you use MaxFrame, prepare the runtime environment. You can access MaxFrame by using the standard MaxFrame SDK (local client) or a DataWorks node.
Prerequisites
-
Python 3.6 or later is installed.
-
A MaxCompute project is created. For more information, see Create a MaxCompute project.
Step 1: Activate MaxFrame
MaxFrame is in invitational preview. Scan the following QR code with DingTalk to join the MaxFrame user support group and contact technical support to activate MaxFrame.

Step 2: Install and access MaxFrame
You can access MaxFrame by using a local client or a MaxFrame node in Dataworks.
Example description: The following example creates a MaxCompute table, uses MaxFrame to process data, and stores the results in another MaxCompute table.
Access MaxFrame from a local client
-
In a system CLI, such as the Windows Command Prompt, run the pip command to install the MaxFrame client. Sample command:
pip install maxframe -
Create a MaxFrame session.
-
Create a
.pyfile, such astest.py, copy the following sample code to thetest.pyfile, and then save the file.import os import maxframe.dataframe as md from odps import ODPS from maxframe import new_session # Create a MaxCompute entry. o = ODPS( # Set the environment variable ALIBABA_CLOUD_ACCESS_KEY_ID to the AccessKey ID of your Alibaba Cloud account. # Set the environment variable ALIBABA_CLOUD_ACCESS_KEY_SECRET to the AccessKey secret of your Alibaba Cloud account. # We recommend that you do not directly use the actual AccessKey ID and AccessKey secret. os.getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), os.getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'), project='your-default-project', endpoint='your-end-point', ) table = o.create_table("test_source_table", "a string, b bigint", if_not_exists=True) with table.open_writer() as writer: writer.write([ ["value1", 0], ["value2", 1], ]) # Create a MaxFrame session. session = new_session(o) df = md.read_odps_table("test_source_table",index_col="b") df["a"] = "prefix_" + df["a"] # Print DataFrame data. print(df.execute().fetch()) # Write data from MaxFrame DataFrame to a MaxCompute table. md.to_odps_table(df, "test_prefix_source_table").execute() # Destroy the MaxFrame session. session.destroy()Parameters:
-
ALIBABA_CLOUD_ACCESS_KEY_ID: The AccessKey ID of the Alibaba Cloud account that has the MaxCompute permissions on the objects that you want to manage in your MaxCompute project. You can obtain the AccessKey ID on the AccessKey Pair page in the Alibaba Cloud Management Console.
-
ALIBABA_CLOUD_ACCESS_KEY_SECRET: The AccessKey secret that corresponds to the AccessKey ID.
-
your-default-project: The name of your MaxCompute project. Log on to the MaxCompute console and choose Workspace > Projects in the left-side navigation pane to view the project name.
-
your_end_point: The endpoint of the region in which your MaxCompute project resides. For more information, see Endpoints.
-
-
Go to the path of the
test.pyfile and run the file. Sample command:python test.py
-
Access MaxFrame by using DataWorks
DataWorks integrates MaxFrame with PyODPS 3 nodes, providing task scheduling capabilities. You can use PyODPS 3 nodes to develop and run MaxFrame jobs.
-
Create a PyODPS 3 node.
You can create a PyODPS 3 node on the DataStudio page of the DataWorks console. For more information, see Develop a PyODPS 3 task.
-
Create a MaxFrame session.
PyODPS 3 integrates MaxCompute user and project information, so you can create MaxFrame sessions directly. Sample code:
import maxframe.dataframe as md from maxframe import new_session from maxframe.config import options options.sql.enable_mcqa = False table = o.create_table("test_source_table", "a string, b bigint", if_not_exists=True) with table.open_writer() as writer: writer.write([ ["value1", 0], ["value2", 1], ]) # Create a MaxFrame session. session = new_session(o) df = md.read_odps_table("test_source_table",index_col="b") df["a"] = "prefix_" + df["a"] # Print DataFrame data. print(df.execute().fetch()) # Write data from MaxFrame DataFrame to a MaxCompute table. md.to_odps_table(df, "test_prefix_source_table").execute() # Destroy the MaxFrame session. session.destroy()
Step 3: Verify the result
Run the Python code and query data in the result table. If the result meets your expectation, MaxFrame is installed and connected to MaxCompute.
-
Run the Python code. The following result is returned:
b a 0 prefix_value1 1 prefix_value2 -
Execute the following SQL statement in the MaxCompute project to query data in the
test_prefix_source_tabletable:SELECT * FROM test_prefix_source_table;The following result is returned:
+------------+------------+ | b | a | +------------+------------+ | 0 | prefix_value1 | | 1 | prefix_value2 | +------------+------------+