Skip to content

Commit aee0fe0

Browse files
committed
requested documentation changes
Signed-off-by: Lorenzo Curcio <[email protected]>
1 parent 92d11b0 commit aee0fe0

File tree

2 files changed

+64
-66
lines changed

2 files changed

+64
-66
lines changed

daprdocs/content/en/python-sdk-docs/python-sdk-actors/_index.md

-59
This file was deleted.

daprdocs/content/en/python-sdk-docs/python-sdk-actors/python-mock-actors.md renamed to daprdocs/content/en/python-sdk-docs/python-sdk-actors/python-actor.md

+64-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,71 @@
11
---
22
type: docs
3-
title: "Dapr Python SDK mock actor unit tests"
4-
linkTitle: "Mock Actors"
5-
weight: 200000
6-
description: How to unit test actor methods using mock actors
3+
title: "Getting started with the Dapr actor Python SDK"
4+
linkTitle: "Actor"
5+
weight: 20000
6+
description: How to get up and running with the Dapr Python SDK
77
---
88

9+
The Dapr actor package allows you to interact with Dapr virtual actors from a Python application.
10+
11+
## Pre-requisites
12+
13+
- [Dapr CLI]({{< ref install-dapr-cli.md >}}) installed
14+
- Initialized [Dapr environment]({{< ref install-dapr-selfhost.md >}})
15+
- [Python 3.8+](https://www.python.org/downloads/) installed
16+
- [Dapr Python package]({{< ref "python#installation" >}}) installed
17+
18+
## Actor interface
19+
20+
The interface defines the actor contract that is shared between the actor implementation and the clients calling the actor. Because a client may depend on it, it typically makes sense to define it in an assembly that is separate from the actor implementation.
21+
22+
```python
23+
from dapr.actor import ActorInterface, actormethod
24+
25+
class DemoActorInterface(ActorInterface):
26+
@actormethod(name="GetMyData")
27+
async def get_my_data(self) -> object:
28+
...
29+
```
30+
31+
## Actor services
32+
33+
An actor service hosts the virtual actor. It is implemented a class that derives from the base type `Actor` and implements the interfaces defined in the actor interface.
34+
35+
Actors can be created using one of the Dapr actor extensions:
36+
- [FastAPI actor extension]({{< ref python-fastapi.md >}})
37+
- [Flask actor extension]({{< ref python-flask.md >}})
38+
39+
## Actor client
40+
41+
An actor client contains the implementation of the actor client which calls the actor methods defined in the actor interface.
42+
43+
```python
44+
import asyncio
45+
46+
from dapr.actor import ActorProxy, ActorId
47+
from demo_actor_interface import DemoActorInterface
48+
49+
async def main():
50+
# Create proxy client
51+
proxy = ActorProxy.create('DemoActor', ActorId('1'), DemoActorInterface)
52+
53+
# Call method on client
54+
resp = await proxy.GetMyData()
55+
```
56+
57+
## Sample
58+
59+
Visit [this page](https://github.com/dapr/python-sdk/tree/release-1.0/examples/demo_actor) for a runnable actor sample.
60+
61+
62+
## Mock Actor Testing
63+
964
The Dapr Python SDK provides the ability to create mock actors to unit test your actor methods and how they interact with the actor state.
1065

11-
## Basic Usage
66+
### Sample Usage
67+
68+
1269
```
1370
from dapr.actor.runtime.mock_actor import create_mock_actor
1471
@@ -40,7 +97,7 @@ result = await mock_actor.recieve_reminder(name, state, due_time, period, _ttl)
4097
# Test the result directly or test for side effects (like changing state) by querying _state_manager._mock_state
4198
```
4299

43-
## Usage and Limitations
100+
### Usage and Limitations
44101

45102
**The \_on\_activate method will not be called automatically the way it is when Dapr initializes a new Actor instance. You should call it manually as needed as part of your tests.**
46103

@@ -57,7 +114,7 @@ The actor _runtime_ctx variable is set to None. Obviously all the normal actor m
57114

58115
The actor _state_manager is overwritten with an instance of MockStateManager. This has all the same methods and functionality of the base ActorStateManager, except for using the various _mock variables for storing data instead of the _runtime_ctx. If your code implements its own custom state manager it will be overwritten and your code will likely break.
59116

60-
## Type Hinting
117+
### Type Hinting
61118

62119
Because of Python's lack of a unified method for type hinting type intersections (see: [python/typing #213](https://github.com/python/typing/issues/213)), type hinting is unfortunately mostly broken with Mock Actors. The return type is type hinted as "instance of Actor subclass T" when it should really be type hinted as "instance of MockActor subclass T" or "instance of type intersection [Actor subclass T, MockActor]" (where, it is worth noting, MockActor is itself a subclass of Actor).
63120

0 commit comments

Comments
 (0)