---
title: Enabling the Python Profiler
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Continuous Profiler > Enabling the Profiler > Enabling the Python
  Profiler
---

# Enabling the Python Profiler

The profiler is shipped within Datadog tracing libraries. If you are already using [APM to collect traces](https://docs.datadoghq.com/tracing/trace_collection.md) for your application, you can skip installing the library and go directly to enabling the profiler.

## Requirements{% #requirements %}

To use profiling, ensure the following requirements are met:

- Enable profiling through the Datadog tracing library. Using the latest stable release is recommended.
- Verify your Python and tracing library versions are compatible by reviewing the [Python Compatibility Requirements](https://docs.datadoghq.com/tracing/trace_collection/compatibility/python.md). **Note**: Some features depend on newer Python versions than the minimum required version for the tracing library. For more details, read [Profile Types](https://docs.datadoghq.com/profiler/profile_types.md?tab=python).

For a summary of the minimum and recommended runtime and tracer versions across all languages, read [Supported Language and Tracer Versions](https://docs.datadoghq.com/profiler/enabling/supported_versions.md).

The installation requires pip version 18 or above.

Continuous Profiler support is in Preview for some serverless platforms, such as [AWS Lambda](https://docs.datadoghq.com/serverless/aws_lambda/profiling.md).

## Installation{% #installation %}

Ensure Datadog Agent v6+ is installed and running. Datadog recommends using [Datadog Agent v7+](https://app.datadoghq.com/account/settings/agent/latest?platform=overview).

Install `ddtrace`, which provides both tracing and profiling functionalities:

```shell
pip install ddtrace
```

If you are using a platform where `ddtrace` binary distribution is not available, first install a development environment.

For example, on Alpine Linux, this can be done with:

```shell
apk install gcc musl-dev linux-headers
```

## Usage{% #usage %}

To automatically profile your code, set the `DD_PROFILING_ENABLED` environment variable to `true` when you use `ddtrace-run`:

```
DD_PROFILING_ENABLED=true \
DD_ENV=prod \
DD_SERVICE=my-web-app \
DD_VERSION=1.0.3 \
ddtrace-run python app.py
```

See Configuration for more advanced usage.

Optionally, set up [Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration.md?tab=python) to connect your profiling data with your Git repositories.

A couple of minutes after you start your application, your profiles appear on the [Datadog APM > Profiler page](https://app.datadoghq.com/profiling). If they do not, refer to the [Troubleshooting](https://docs.datadoghq.com/profiler/profiler_troubleshooting/python.md) guide.

If you want to manually control the lifecycle of the profiler, use the `ddtrace.profiling.Profiler` object:

```python
from ddtrace.profiling import Profiler

prof = Profiler(
    env="prod",  # if not specified, falls back to environment variable DD_ENV
    service="my-web-app",  # if not specified, falls back to environment variable DD_SERVICE
    version="1.0.3",   # if not specified, falls back to environment variable DD_VERSION
)
prof.start()  # Should be as early as possible, eg before other imports, to ensure everything is profiled
```

## Caveats{% #caveats %}

When your process forks using `os.fork`, the profiler is automatically restarted in the child process on supported Python versions. No manual restart is required.

## Configuration{% #configuration %}

You can configure the profiler using the [environment variables](https://ddtrace.readthedocs.io/en/stable/configuration.html#configuration).

### Code provenance{% #code-provenance %}

The Python profiler supports code provenance reporting, which provides insight into the library that is running the code. While this is enabled by default, you can turn it off by setting `DD_PROFILING_ENABLE_CODE_PROVENANCE=0`.

## Not sure what to do next?{% #not-sure-what-to-do-next %}

The [Getting Started with Profiler](https://docs.datadoghq.com/getting_started/profiler.md) guide takes a sample service with a performance problem and shows you how to use Continuous Profiler to understand and fix the problem.

## Further Reading{% #further-reading %}

- [Getting Started with Profiler](https://docs.datadoghq.com/getting_started/profiler.md)
- [Learn more about available profile visualizations](https://docs.datadoghq.com/profiler/profile_visualizations.md)
- [Fix problems you encounter while using the profiler](https://docs.datadoghq.com/profiler/profiler_troubleshooting/python.md)
