When you run Python microservices across distributed environments, you need centralized trace collection to diagnose latency and map service dependencies. The Apache SkyWalking Python agent automatically instruments supported libraries and reports trace data to Managed Service for OpenTelemetry over gRPC. You get distributed traces and dependency maps without code changes.
How it works
Download the SkyWalking Python agent and configure it with your Managed Service for OpenTelemetry endpoint and authentication token.
The agent automatically instruments supported libraries in your Python application.
The agent reports trace data over gRPC to Managed Service for OpenTelemetry, where you can view distributed traces and dependency maps.
Background information
SkyWalking is a popular application performance monitoring (APM) service developed in China. It is designed for microservices, cloud-native architectures, and containers such as Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.
SkyWalking-Python is the official Python agent repository of SkyWalking. You can use SkyWalking-Python to monitor Python applications. SkyWalking-Python can automatically instrument third-party repositories such as Kafka, AIOHTTP, Redis, and WebSockets. For the full list, see Supported libraries.
Prerequisites
Python 3.7 or later is installed
The Python agent of Apache SkyWalking is downloaded. We recommend that you download the latest version of the Python agent.
SkyWalking-Python is referenced in your Python project
The SkyWalking endpoint and authentication token from the Managed Service for OpenTelemetry console. See Get the SkyWalking endpoint
Get the SkyWalking endpoint
Log on to the Managed Service for OpenTelemetry console.
In the left-side navigation pane, click Cluster Configurations. On the page that appears, click the Access point information tab.
In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.
Set the Client parameter to SkyWalking.
In the Related Information column, copy the endpoint for your deployment scenario:
Scenario Endpoint type When to use Alibaba Cloud production environment VPC endpoint Your application runs on an Alibaba Cloud VPC External or local development Public endpoint Your application runs outside Alibaba Cloud 
Set up instrumentation
You can configure the parameters of the SkyWalking Python agent directly in a Python project or by defining environment variables.
Option 1: Configure the parameters in a Python project
Modify the config.init parameters in the Python project file. The general pattern is:
from skywalking import config
config.init(ConfigurationName = ConfigurationValue)In the sample code, the proxy/TestProxy.py and controller/TestController.py files are used.
Configure the endpoint and the authentication token. Replace
<endpoint>and<auth-token>with the endpoint and authentication token obtained in the prerequisites.from skywalking import agent, config config.init( agent_collector_backend_services='<endpoint>', agent_authentication='<auth-token>' )Configure a service name as the application identifier.
config.init(agent_name='<service name>')Specify a protocol over which data is reported. SkyWalking supports gRPC.
config.init(agent_protocol='<protocol>')Configure optional parameters based on your business requirements. For a complete list of configuration parameters, see the Apache SkyWalking Python agent configuration reference.
Restart the application.
Option 2: Configure the parameters by defining environment variables
Add the following content to the environment variable file and refresh the file to make the modified file take effect. The general pattern is:
export SW_AGENT_ConfigurationName=ConfigurationValueFor Docker containers, you can configure environment variables in the environment directory of the docker-compose.yaml file.
Sample code
A sample Flask application that demonstrates SkyWalking integration is available on GitHub: skywalking-demo.
The sample application routes HTTP requests through two services (proxy/TestProxy.py and controller/TestController.py) and performs MySQL database operations. After trace data is reported, you can view cross-service traces and MySQL call metrics in the Managed Service for OpenTelemetry console.
FAQ
Q: Method not found: skywalking.v3.LogReportService/collect appears in the logs. How do I fix it?

Managed Service for OpenTelemetry does not support the SkyWalking log reporting protocol. Disable the log reporter by setting the agent_log_reporter_active parameter nested under config.init to False:
config.init(agent_log_reporter_active=False)Q: Method not found: skywalking.v3.MeterReportService/collect appears when reporting data over gRPC. How do I fix it?

You cannot report metrics to the console. Disable the meter reporter by setting the agent_meter_reporter_active parameter nested under config.init to False:
config.init(agent_meter_reporter_active=False)Supported libraries
The SkyWalking Python agent automatically instruments the following libraries. No additional configuration is required.
| Library | Python version | Supported library version | Plug-in name |
|---|---|---|---|
| aiohttp | 3.7+ | 3.7.* | sw_aiohttp |
| aioredis | 3.7+ | 2.0.* | sw_aioredis |
| aiormq | 3.7+ | 6.3, 6.4 | sw_aiormq |
| amqp | 3.7+ | 2.6.1 | sw_amqp |
| asyncpg | 3.7+ | 0.25.0 | sw_asyncpg |
| bottle | 3.7+ | 0.12.23 | sw_bottle |
| celery | 3.7+ | 5.1 | sw_celery |
| confluent_kafka | 3.7+ | 1.5.0, 1.7.0, 1.8.2 | sw_confluent_kafka |
| django | 3.7+ | 3.2 | sw_django |
| elasticsearch | 3.7+ | 7.13, 7.14, 7.15 | sw_elasticsearch |
| falcon | 3.7+ | 2.4.1, 2.5, 2.6 (not supported on 3.11+) | sw_falcon |
| fastapi | 3.7+ | 0.88.*, 0.89.* | sw_fastapi |
| flask | 3.7+ | 2.0 | sw_flask |
| happybase | 3.7+ | 1.2.0 | sw_happybase |
| http.server | 3.7+ | * | sw_http_server |
| werkzeug | 3.7+ | 1.0.1, 2.0 | sw_http_server |
| httpx | 3.7+ | 0.22.*, 0.23.* | sw_httpx |
| kafka-python | 3.7+ | 2.0 | sw_kafka |
| loguru | 3.7+ | 0.6.0, 0.7.0 | sw_loguru |
| mysqlclient | 3.7+ | 2.1.* | sw_mysqlclient |
| neo4j | 3.7+ | 5.* | sw_neo4j |
| psycopg\[binary\] | 3.7+ | 3.0.18, 3.1.* | sw_psycopg |
| psycopg2-binary | 3.7+ (not supported on 3.10+) | 2.9 | sw_psycopg2 |
| pymongo | 3.7+ | 3.11.* | sw_pymongo |
| pymysql | 3.7+ | 1.0 | sw_pymysql |
| pyramid | 3.7+ | 1.10, 2.0 | sw_pyramid |
| pika | 3.7+ | 1.2 | sw_rabbitmq |
| redis | 3.7+ | 3.5.*, 4.5.1 | sw_redis |
| requests | 3.7+ | 2.25, 2.26 | sw_requests |
| sanic | 3.7+ (not supported on 3.10+) | 20.12 | sw_sanic |
| tornado | 3.7+ | 6.0, 6.1 | sw_tornado |
| urllib3 | 3.7+ | 1.25, 1.26 | sw_urllib3 |
| urllib.request | 3.7+ | * | sw_urllib_request |
| websockets | 3.7+ | 10.3, 10.4 | sw_websockets |
What's next
Explore the SkyWalking Python agent configuration reference to fine-tune agent behavior.
Review the skywalking-demo sample project for a working Flask + MySQL example.