This topic introduces Python on MaxCompute (PyODPS) and its common usage.

Background information

PyODPS is the MaxCompute SDK for Python. PyODPS supports the DataFrame framework and basic operations on MaxCompute objects. You can use PyODPS to analyze data in MaxCompute.

PyODPS supports Python 2.6 and later, and Python 3.

Read the following documentation to get familiar with PyODPS:
If you have the interest to help build the PyODPS ecosystem, you can perform the following operations:
  • Cooperate in writing PyODPS documentation.
  • Develop PyODPS code at GitHub.
  • Join the DingTalk group for technical communication. To join, find and enter group number 11701793.

Initialization

Before you use PyODPS, run the following command to initialize a connection to MaxCompute by using your Alibaba Cloud account:
from odps import ODPS
odps = ODPS('**your-access-id**', '**your-secret-access-key**', '**your-default-project**',endpoint='**your-end-point**')
Parameter description:
  • your-access-id: the AccessKey ID of your Alibaba Cloud account.
  • your-secret-access-key: the AccessKey secret of your Alibaba Cloud account.
  • your-default-project: the name of the project.
  • your-end-point: the endpoint of the region where your MaxCompute project resides. For more information, see Configure endpoints.

After you initialize the connection, you can use PyODPS to manage MaxCompute objects, such as tables, resources, and functions.

Method description

The following table lists the available basic methods that PyODPS provides for you to use on MaxCompute objects.
Item Method Description
Project get_project(project_name) Obtains a project.
exist_project(project_name) Checks whether a project exists.
Table list_tables() Lists all tables in a project.
exist_table(table_name) Checks whether a table exists.
get_table(table_name,project=project_name) Obtains a specified table in the current project or another specified project.
create_table() Creates a table.
read_table() Reads data from a table.
write_table() Writes data to a table.
delete_table() Deletes a table.
Table partition exist_partition() Checks whether a partition exists.
get_partition() Obtains a partition.
create_partition() Creates a partition.
delete_partition() Deletes a partition.
SQL execute_sql()/run_sql() Executes an SQL statement.
open_reader() Reads execution results.
Instance list_instances() Lists all instances in a project.
exist_instance() Checks whether an instance exists.
get_instance() Obtains an instance.
stop_instance() Terminates an instance.
Resource create_resource() Creates a resource.
open_resource() Opens a resource.
get_resource() Obtains a resource.
list_resources() Lists all resources.
exist_resource() Checks whether a resource exists.
delete_resource() Deletes a resource.
Function create_function() Creates a function.
delete_function() Deletes a function.
Data upload or download channel create_upload_session() Creates a session that uploads data.
create_download_session() Creates a session that downloads data.