Python
Dapr offers a variety of subpackages to help with the development of Python applications. Using them you can create Python clients, servers, and virtual actors with Dapr.
Prerequisites
- Dapr CLI installed
- Initialized Dapr environment
- Python 3.10+ installed
Installation
To get started with the Python SDK, install the main Dapr Python SDK package.
pip install dapr
Note: The development version will contain features and behavior that will be compatible with the pre-release version of the Dapr runtime. Only tagged releases are published to PyPI, so install the development version from the GitHub repository. Make sure to uninstall any stable versions of the Python SDK before installing it.
pip install "dapr @ git+https://github.com/dapr/python-sdk.git@main"
The SDK requires protobuf 6.33.5 or later and grpcio and grpcio-status 1.81.1 or later. pip installs matching versions automatically. If your project pins protobuf, grpcio or grpcio-status to an earlier version, update the pins before you upgrade the SDK.
Install extensions
From Dapr 1.19, the SDK extensions are optional extras of the dapr package. Install the extras that you need in the same command as the SDK, for example:
pip install "dapr[workflow]"
pip install "dapr[fastapi,grpc]"
| Extra | Extension | Import path |
|---|---|---|
dapr[fastapi] | FastAPI | dapr.ext.fastapi |
dapr[flask] | Flask | dapr.ext.flask |
dapr[grpc] | gRPC | dapr.ext.grpc |
dapr[workflow] | Workflow | dapr.ext.workflow |
dapr[databricks] | Databricks | dapr.ext.databricks |
dapr[langgraph] | LangGraph checkpoint persistence | dapr.ext.langgraph |
dapr[strands] | Strands agent session management | dapr.ext.strands |
To install every extension, use pip install "dapr[all]".
Upgrading from Dapr 1.18 or earlier
The dapr-ext-fastapi, dapr-ext-grpc, dapr-ext-langgraph, dapr-ext-strands, dapr-ext-workflow and flask-dapr packages are no longer published. The extension code now ships inside the dapr package, and the import paths under dapr.ext.* do not change.
If you have any of the old packages installed, run these commands in order. Uninstalling an old package removes the extension files that the new dapr package installs, so you must reinstall dapr afterwards:
pip uninstall -y dapr-ext-fastapi dapr-ext-grpc dapr-ext-langgraph dapr-ext-strands dapr-ext-workflow flask-dapr
pip install --force-reinstall --no-deps dapr
pip install "dapr[fastapi,workflow]"
Replace the extras in the last command with the extras your application uses. If you skip these steps, import dapr emits a FutureWarning with the recovery command. You can silence the warning by setting DAPR_SKIP_LEGACY_CHECK=1.
Available subpackages
SDK imports
Python SDK imports are subpackages included with the main SDK install, but need to be imported when used. The most common imports provided by the Dapr Python SDK are:
Learn more about all of the available Dapr Python SDK imports.
SDK extensions
SDK extensions mainly work as utilities for receiving pub/sub events, programatically creating pub/sub subscriptions, and handling input binding events. While you can acheive all of these tasks without an extension, using a Python SDK extension proves convenient.
Learn more about the Dapr Python SDK extensions.
Try it out
Clone the Python SDK repo.
git clone https://github.com/dapr/python-sdk.git
Walk through the Python quickstarts, tutorials, and examples to see Dapr in action:
| SDK samples | Description |
|---|---|
| Quickstarts | Experience Dapr’s API building blocks in just a few minutes using the Python SDK. |
| SDK samples | Clone the SDK repo to try out some examples and get started. |
| Bindings tutorial | See how Dapr Python SDK works alongside other Dapr SDKs to enable bindings. |
| Distributed Calculator tutorial | Use the Dapr Python SDK to handle method invocation and state persistent capabilities. |
| Hello World tutorial | Learn how to get Dapr up and running locally on your machine with the Python SDK. |
| Hello Kubernetes tutorial | Get up and running with the Dapr Python SDK in a Kubernetes cluster. |
| Observability tutorial | Explore Dapr’s metric collection, tracing, logging and health check capabilities using the Python SDK. |
| Pub/sub tutorial | See how Dapr Python SDK works alongside other Dapr SDKs to enable pub/sub applications. |