All Products
Search
Document Center

Cloud Monitor:Manually install the Python agent

Last Updated:Sep 28, 2025

After you install the agent for a Python application, Application Monitoring starts monitoring the application. You can view monitoring data, such as the application topology, call chains, and SQL analysis.

Note
  • For applications deployed in a Kubernetes environment, do not manually install the agent. Instead, install a component to connect to Application Monitoring. For more information, see Install the Python agent for Container Service for Kubernetes (ACK) and Container Compute Service (ACS) using the ack-onepilot component.

  • If you have questions about using the Python agent, see the FAQ for the Python agent. If the document does not answer your questions, you can contact us through the DingTalk group. The group ID is 35568145.

Before you begin

  • Make sure the environment where the application resides is connected to Alibaba Cloud over the Internet or an internal network, and the security group of the environment allows outbound traffic for TCP ports 80 and 443.

  • Check the versions of Python and frameworks. For more information, see Python libraries supported by Application Monitoring.

Usage notes

  • If the application is started by using Uvicorn, replace the command to install the agent.

    For example, if the following command is used to start your application:

    uvicorn -w 4 -b 0.0.0.0:8000 app:app

    Replace the command with the following:

    aliyun-instrument gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 app:app
    Note

    The aliyun-instrument command initializes the ARMS agent for Python and instruments data in a non-intrusive way.

  • If you use gevent coroutines, set the environment variable GEVENT_ENABLE=true.

    Example:

    from gevent import monkey
    monkey.patch_all()

    Run the following command to set the environment variable:

    GEVENT_ENABLE=true

Step 1: Download aliyun-bootstrap

Download the agent installer, aliyun-bootstrap, from the Python Package Index (PyPI) repository.

pip3 install aliyun-bootstrap

Step 2: Configure environment variables

Manually add the following environment variables for your Python application:

# Method 1: Add environment variables for all processes in the current shell
export ARMS_APP_NAME=xxx   # The application name.
export ARMS_WORKSPACE=xxx   # Replace with the name of your workspace.
export ARMS_REGION_ID=xxx   # The region ID of your Alibaba Cloud account.
export ARMS_LICENSE_KEY=xxx   # The Alibaba Cloud license key.
export ARMS_IS_PUBLIC=True   # Add this environment variable to use public network access.
# Method 2: Add environment variables for a single process
ARMS_APP_NAME=xxx ARMS_WORKSPACE=xxx ARMS_REGION_ID=xxx ARMS_LICENSE_KEY=xxx ARMS_IS_PUBLIC=True aliyun-instrument xxx.py

You can obtain the license key by calling the OpenAPI. For more information, see DescribeTraceLicenseKey - List LicenseKey.

(Optional) Installation in a Docker environment

For a Docker environment, modify your Dockerfile based on the following example.

# Add environment variables
ENV ARMS_APP_NAME={AppName}
ENV ARMS_REGION_ID={regionId}
ENV ARMS_LICENSE_KEY={licenseKey}
ENV ARMS_WORKSPACE={workspace}

## Original environment

Step 3: Install the Python agent using aliyun-bootstrap

  1. To speed up the installation, run the following command to configure the image repository.

    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip config set install.trusted-host mirrors.aliyun.com
  2. Install the agent.

    aliyun-bootstrap -a install
    Note

    To install a specific version of the Python agent, run the following command:

    # Replace ${version} with the actual version number.
    aliyun-bootstrap -a install -v ${version}

    For a list of all released Python agent versions, see Python Agent Version Guide.

Step 4: Start the application

To start the application by using the ARMS agent for Python, run the following command:

aliyun-instrument python app.py

View monitoring details

  1. Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, choose Application Center > O&M and Monitoring > Application Monitoring.

  2. On the Application List page, find your application. Click the application name to view detailed monitoring data.