Skip to main content

Python Agent for Apache SkyWalking

Project description

SkyWalking Python Agent

Sky Walking logo

SkyWalking-Python: The Python Agent for Apache SkyWalking, which provides the native tracing abilities for Python project.

SkyWalking: an APM(application performance monitor) system, especially designed for microservices, cloud native and container-based (Docker, Kubernetes, Mesos) architectures.

GitHub stars Twitter Follow



From Pypi

The Python agent module is published to Pypi, from where you can use pip to install:

# Install the latest version, using the default gRPC protocol to report data to OAP
pip install "apache-skywalking"

# Install the latest version, using the http protocol to report data to OAP
pip install "apache-skywalking[http]"

# Install the latest version, using the kafka protocol to report data to OAP
pip install "apache-skywalking[kafka]"

# Install a specific version x.y.z
# pip install apache-skywalking==x.y.z
pip install apache-skywalking==0.1.0  # For example, install version 0.1.0 no matter what the latest version is

From Source Codes

Refer to the FAQ.

Set up Python Agent

SkyWalking Python SDK requires SkyWalking 8.0+ and Python 3.5+.

If you want to try out the latest features that are not released yet, please refer to the guide to build from sources.

from skywalking import agent, config

config.init(collector='', service='your awesome service')

Alternatively, you can also pass the configurations via environment variables (such as SW_AGENT_NAME, SW_AGENT_COLLECTOR_BACKEND_SERVICES, etc.) so that you don't need to call config.init.

All supported environment variables can be found here

Supported Libraries

There are some built-in plugins (such as http.server, Flask, Django etc.) that support automatic instrumentation of Python libraries, the complete lists can be found here


Apart from the libraries that can be instrumented automatically, we also provide some APIs to enable manual instrumentation.

Create Spans

The code snippet below shows how to create entry span, exit span and local span.

from skywalking import Component
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.tags import Tag

context: SpanContext = get_context()  # get a tracing context
# create an entry span, by using `with` statement,
# the span automatically starts/stops when entering/exiting the context
with context.new_entry_span(op='') as span:
    span.component = Component.Flask
# the span automatically stops when exiting the `with` context

with context.new_exit_span(op='', peer='localhost:8080') as span:
    span.component = Component.Flask

with context.new_local_span(op='') as span:
    span.tag(Tag(key='Singer', val='Nakajima'))


from time import sleep

from skywalking import Component
from skywalking.decorators import trace, runnable
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.ipc.process import SwProcess

@trace()  # the operation name is the method name('some_other_method') by default
def some_other_method():

@trace(op='awesome')  # customize the operation name to 'awesome'
def some_method():

async def async_func():
    return 'asynchronous'

async def async_func2():
    return await async_func()

@runnable() # cross thread propagation
def some_method(): 

from threading import Thread 
t = Thread(target=some_method)

# When another process is started, agents will also be started in other processes, 
# supporting only the process mode of spawn.
p1 = SwProcess(target=some_method) 

context: SpanContext = get_context()
with context.new_entry_span(op=str('')) as span:
    span.component = Component.Flask


Before submitting a pull request or push a commit, please read our contributing and developer guide.


Check the FAQ page or add the FAQs there.


Apache 2.0

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for apache-skywalking, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size apache_skywalking-0.5.0-py3-none-any.whl (161.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size apache-skywalking-0.5.0.tar.gz (51.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page