dapr-ext-fastapi-dev 1.11.0rc1.dev1781__py3-none-any.whl → 1.14.0rc1.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dapr-ext-fastapi-dev might be problematic. Click here for more details.
- dapr/ext/fastapi/__init__.py +1 -4
- dapr/ext/fastapi/actor.py +42 -56
- dapr/ext/fastapi/app.py +33 -27
- dapr/ext/fastapi/version.py +1 -1
- {dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info → dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info}/METADATA +2 -2
- dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/RECORD +9 -0
- {dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info → dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info}/WHEEL +1 -1
- dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/RECORD +0 -9
- {dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info → dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info}/LICENSE +0 -0
- {dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info → dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info}/top_level.txt +0 -0
dapr/ext/fastapi/__init__.py
CHANGED
dapr/ext/fastapi/actor.py
CHANGED
|
@@ -15,7 +15,7 @@ limitations under the License.
|
|
|
15
15
|
|
|
16
16
|
from typing import Any, Optional, Type, List
|
|
17
17
|
|
|
18
|
-
from fastapi import FastAPI, APIRouter, Request, Response, status
|
|
18
|
+
from fastapi import FastAPI, APIRouter, Request, Response, status # type: ignore
|
|
19
19
|
from fastapi.logger import logger
|
|
20
20
|
from fastapi.responses import JSONResponse
|
|
21
21
|
|
|
@@ -23,15 +23,16 @@ from dapr.actor import Actor, ActorRuntime
|
|
|
23
23
|
from dapr.clients.exceptions import DaprInternalError, ERROR_CODE_UNKNOWN
|
|
24
24
|
from dapr.serializers import DefaultJSONSerializer
|
|
25
25
|
|
|
26
|
-
DEFAULT_CONTENT_TYPE =
|
|
26
|
+
DEFAULT_CONTENT_TYPE = 'application/json; utf-8'
|
|
27
27
|
DAPR_REENTRANCY_ID_HEADER = 'Dapr-Reentrancy-Id'
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def _wrap_response(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
status_code: int,
|
|
32
|
+
msg: Any,
|
|
33
|
+
error_code: Optional[str] = None,
|
|
34
|
+
content_type: Optional[str] = DEFAULT_CONTENT_TYPE,
|
|
35
|
+
):
|
|
35
36
|
resp = None
|
|
36
37
|
if isinstance(msg, str):
|
|
37
38
|
response_obj = {
|
|
@@ -48,9 +49,7 @@ def _wrap_response(
|
|
|
48
49
|
|
|
49
50
|
|
|
50
51
|
class DaprActor(object):
|
|
51
|
-
|
|
52
|
-
def __init__(self, app: FastAPI,
|
|
53
|
-
router_tags: Optional[List[str]] = ['Actor']):
|
|
52
|
+
def __init__(self, app: FastAPI, router_tags: Optional[List[str]] = ['Actor']):
|
|
54
53
|
# router_tags should be added to all magic Dapr Actor methods implemented here
|
|
55
54
|
self._router_tags = router_tags
|
|
56
55
|
self._router = APIRouter()
|
|
@@ -59,7 +58,7 @@ class DaprActor(object):
|
|
|
59
58
|
app.include_router(self._router)
|
|
60
59
|
|
|
61
60
|
def init_routes(self, router: APIRouter):
|
|
62
|
-
@router.get(
|
|
61
|
+
@router.get('/healthz', tags=self._router_tags)
|
|
63
62
|
async def healthz():
|
|
64
63
|
return {'status': 'ok'}
|
|
65
64
|
|
|
@@ -73,96 +72,83 @@ class DaprActor(object):
|
|
|
73
72
|
try:
|
|
74
73
|
await ActorRuntime.deactivate(actor_type_name, actor_id)
|
|
75
74
|
except DaprInternalError as ex:
|
|
76
|
-
return _wrap_response(
|
|
77
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
78
|
-
ex.as_dict())
|
|
75
|
+
return _wrap_response(status.HTTP_500_INTERNAL_SERVER_ERROR, ex.as_dict())
|
|
79
76
|
except Exception as ex:
|
|
80
77
|
return _wrap_response(
|
|
81
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
82
|
-
|
|
83
|
-
ERROR_CODE_UNKNOWN)
|
|
78
|
+
status.HTTP_500_INTERNAL_SERVER_ERROR, repr(ex), ERROR_CODE_UNKNOWN
|
|
79
|
+
)
|
|
84
80
|
|
|
85
81
|
msg = f'deactivated actor: {actor_type_name}.{actor_id}'
|
|
86
82
|
logger.debug(msg)
|
|
87
83
|
return _wrap_response(status.HTTP_200_OK, msg)
|
|
88
84
|
|
|
89
|
-
@router.put(
|
|
90
|
-
|
|
85
|
+
@router.put(
|
|
86
|
+
'/actors/{actor_type_name}/{actor_id}/method/{method_name}', tags=self._router_tags
|
|
87
|
+
)
|
|
91
88
|
async def actor_method(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
method_name: str,
|
|
95
|
-
request: Request):
|
|
89
|
+
actor_type_name: str, actor_id: str, method_name: str, request: Request
|
|
90
|
+
):
|
|
96
91
|
try:
|
|
97
92
|
# Read raw bytes from request stream
|
|
98
93
|
req_body = await request.body()
|
|
99
94
|
reentrancy_id = request.headers.get(DAPR_REENTRANCY_ID_HEADER)
|
|
100
95
|
result = await ActorRuntime.dispatch(
|
|
101
|
-
actor_type_name, actor_id, method_name, req_body, reentrancy_id
|
|
96
|
+
actor_type_name, actor_id, method_name, req_body, reentrancy_id
|
|
97
|
+
)
|
|
102
98
|
except DaprInternalError as ex:
|
|
103
|
-
return _wrap_response(
|
|
104
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR, ex.as_dict())
|
|
99
|
+
return _wrap_response(status.HTTP_500_INTERNAL_SERVER_ERROR, ex.as_dict())
|
|
105
100
|
except Exception as ex:
|
|
106
101
|
return _wrap_response(
|
|
107
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
108
|
-
|
|
109
|
-
ERROR_CODE_UNKNOWN)
|
|
102
|
+
status.HTTP_500_INTERNAL_SERVER_ERROR, repr(ex), ERROR_CODE_UNKNOWN
|
|
103
|
+
)
|
|
110
104
|
|
|
111
105
|
msg = f'called method. actor: {actor_type_name}.{actor_id}, method: {method_name}'
|
|
112
106
|
logger.debug(msg)
|
|
113
107
|
return _wrap_response(status.HTTP_200_OK, result)
|
|
114
108
|
|
|
115
|
-
@router.put(
|
|
116
|
-
|
|
109
|
+
@router.put(
|
|
110
|
+
'/actors/{actor_type_name}/{actor_id}/method/timer/{timer_name}', tags=self._router_tags
|
|
111
|
+
)
|
|
117
112
|
async def actor_timer(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
timer_name: str,
|
|
121
|
-
request: Request):
|
|
113
|
+
actor_type_name: str, actor_id: str, timer_name: str, request: Request
|
|
114
|
+
):
|
|
122
115
|
try:
|
|
123
116
|
# Read raw bytes from request stream
|
|
124
117
|
req_body = await request.body()
|
|
125
118
|
await ActorRuntime.fire_timer(actor_type_name, actor_id, timer_name, req_body)
|
|
126
119
|
except DaprInternalError as ex:
|
|
127
|
-
return _wrap_response(
|
|
128
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
129
|
-
ex.as_dict())
|
|
120
|
+
return _wrap_response(status.HTTP_500_INTERNAL_SERVER_ERROR, ex.as_dict())
|
|
130
121
|
except Exception as ex:
|
|
131
122
|
return _wrap_response(
|
|
132
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
133
|
-
|
|
134
|
-
ERROR_CODE_UNKNOWN)
|
|
123
|
+
status.HTTP_500_INTERNAL_SERVER_ERROR, repr(ex), ERROR_CODE_UNKNOWN
|
|
124
|
+
)
|
|
135
125
|
|
|
136
126
|
msg = f'called timer. actor: {actor_type_name}.{actor_id}, timer: {timer_name}'
|
|
137
127
|
logger.debug(msg)
|
|
138
128
|
return _wrap_response(status.HTTP_200_OK, msg)
|
|
139
129
|
|
|
140
|
-
@router.put(
|
|
141
|
-
|
|
130
|
+
@router.put(
|
|
131
|
+
'/actors/{actor_type_name}/{actor_id}/method/remind/{reminder_name}',
|
|
132
|
+
tags=self._router_tags,
|
|
133
|
+
)
|
|
142
134
|
async def actor_reminder(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
reminder_name: str,
|
|
146
|
-
request: Request):
|
|
135
|
+
actor_type_name: str, actor_id: str, reminder_name: str, request: Request
|
|
136
|
+
):
|
|
147
137
|
try:
|
|
148
138
|
# Read raw bytes from request stream
|
|
149
139
|
req_body = await request.body()
|
|
150
|
-
await ActorRuntime.fire_reminder(
|
|
151
|
-
actor_type_name, actor_id, reminder_name, req_body)
|
|
140
|
+
await ActorRuntime.fire_reminder(actor_type_name, actor_id, reminder_name, req_body)
|
|
152
141
|
except DaprInternalError as ex:
|
|
153
|
-
return _wrap_response(
|
|
154
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
155
|
-
ex.as_dict())
|
|
142
|
+
return _wrap_response(status.HTTP_500_INTERNAL_SERVER_ERROR, ex.as_dict())
|
|
156
143
|
except Exception as ex:
|
|
157
144
|
return _wrap_response(
|
|
158
|
-
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
159
|
-
|
|
160
|
-
ERROR_CODE_UNKNOWN)
|
|
145
|
+
status.HTTP_500_INTERNAL_SERVER_ERROR, repr(ex), ERROR_CODE_UNKNOWN
|
|
146
|
+
)
|
|
161
147
|
|
|
162
148
|
msg = f'called reminder. actor: {actor_type_name}.{actor_id}, reminder: {reminder_name}'
|
|
163
149
|
logger.debug(msg)
|
|
164
150
|
return _wrap_response(status.HTTP_200_OK, msg)
|
|
165
151
|
|
|
166
|
-
async def register_actor(self, actor: Type[Actor]) -> None:
|
|
167
|
-
await ActorRuntime.register_actor(actor)
|
|
152
|
+
async def register_actor(self, actor: Type[Actor], **kwargs) -> None:
|
|
153
|
+
await ActorRuntime.register_actor(actor, **kwargs)
|
|
168
154
|
logger.debug(f'registered actor: {actor.__class__.__name__}')
|
dapr/ext/fastapi/app.py
CHANGED
|
@@ -24,24 +24,24 @@ class DaprApp:
|
|
|
24
24
|
app_instance: The FastAPI instance to wrap.
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
|
-
def __init__(self, app_instance: FastAPI,
|
|
28
|
-
router_tags: Optional[List[str]] = ['PubSub']):
|
|
27
|
+
def __init__(self, app_instance: FastAPI, router_tags: Optional[List[str]] = ['PubSub']):
|
|
29
28
|
# The router_tags should be added to all magic Dapr App PubSub methods implemented here
|
|
30
29
|
self._router_tags = router_tags
|
|
31
30
|
self._app = app_instance
|
|
32
31
|
self._subscriptions: List[Dict[str, object]] = []
|
|
33
32
|
|
|
34
|
-
self._app.add_api_route(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
self._app.add_api_route(
|
|
34
|
+
'/dapr/subscribe', self._get_subscriptions, methods=['GET'], tags=self._router_tags
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def subscribe(
|
|
38
|
+
self,
|
|
39
|
+
pubsub: str,
|
|
40
|
+
topic: str,
|
|
41
|
+
metadata: Optional[Dict[str, str]] = {},
|
|
42
|
+
route: Optional[str] = None,
|
|
43
|
+
dead_letter_topic: Optional[str] = None,
|
|
44
|
+
):
|
|
45
45
|
"""
|
|
46
46
|
Subscribes to a topic on a pub/sub component.
|
|
47
47
|
|
|
@@ -73,21 +73,27 @@ class DaprApp:
|
|
|
73
73
|
Returns:
|
|
74
74
|
The decorator for the function.
|
|
75
75
|
"""
|
|
76
|
+
|
|
76
77
|
def decorator(func):
|
|
77
|
-
event_handler_route = f
|
|
78
|
-
|
|
79
|
-
self._app.add_api_route(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
event_handler_route = f'/events/{pubsub}/{topic}' if route is None else route
|
|
79
|
+
|
|
80
|
+
self._app.add_api_route(
|
|
81
|
+
event_handler_route, func, methods=['POST'], tags=self._router_tags
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
self._subscriptions.append(
|
|
85
|
+
{
|
|
86
|
+
'pubsubname': pubsub,
|
|
87
|
+
'topic': topic,
|
|
88
|
+
'route': event_handler_route,
|
|
89
|
+
'metadata': metadata,
|
|
90
|
+
**(
|
|
91
|
+
{'deadLetterTopic': dead_letter_topic}
|
|
92
|
+
if dead_letter_topic is not None
|
|
93
|
+
else {}
|
|
94
|
+
),
|
|
95
|
+
}
|
|
96
|
+
)
|
|
91
97
|
|
|
92
98
|
return decorator
|
|
93
99
|
|
dapr/ext/fastapi/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dapr-ext-fastapi-dev
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.14.0rc1.dev2
|
|
4
4
|
Summary: The developmental release for Dapr FastAPI extension.
|
|
5
5
|
Home-page: https://dapr.io/
|
|
6
6
|
Author: Dapr Authors
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
22
|
Requires-Python: >=3.8
|
|
23
23
|
License-File: LICENSE
|
|
24
|
-
Requires-Dist: dapr-dev >=1.
|
|
24
|
+
Requires-Dist: dapr-dev >=1.13.0rc1.dev
|
|
25
25
|
Requires-Dist: uvicorn >=0.11.6
|
|
26
26
|
Requires-Dist: fastapi >=0.60.1
|
|
27
27
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
dapr/ext/fastapi/__init__.py,sha256=fs-DJZe2wY4zn7jC9KfpSLP0RJKrAekfbfyxW-dsZO8,679
|
|
2
|
+
dapr/ext/fastapi/actor.py,sha256=Tu7-k3ulJfbsp5UrGAIA8LOp0DbGtwfLxgUnxRlZnlc,6558
|
|
3
|
+
dapr/ext/fastapi/app.py,sha256=npOC9jEaycXCADiF6w-ENtLJrluPOuG6WRmKr1ldIm8,3747
|
|
4
|
+
dapr/ext/fastapi/version.py,sha256=-RfJ_K9ZWVu8wf99edkDO56-_mci9MgDvADnB7FTX7o,618
|
|
5
|
+
dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/LICENSE,sha256=D-QjNdE9_ypCaJn2kkQy-AYHZZ_x5aozSpR7Q1CpbRs,11377
|
|
6
|
+
dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/METADATA,sha256=mWW33ilIbw8gje27n31CKQ2c8y1lqyh4Fn_MYrAJAAE,1087
|
|
7
|
+
dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
8
|
+
dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/top_level.txt,sha256=iLDu9C_1nUTIsa3H4jMbuHuF-zs0opkitR7p7PCPYz0,5
|
|
9
|
+
dapr_ext_fastapi_dev-1.14.0rc1.dev2.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
dapr/ext/fastapi/__init__.py,sha256=yTwj4FKfaSEsCQWNfqQd90QPP-lj_oguy7XDgyVWRkc,689
|
|
2
|
-
dapr/ext/fastapi/actor.py,sha256=7mNs2EWbyk8C6q2C2Bd4JJ8WCKtJWYo0th_tRBo5Ypc,6921
|
|
3
|
-
dapr/ext/fastapi/app.py,sha256=kAYZfv-ojAg3KhaFl3j3m_wCB3tPNL-6EGd8aAuzBIY,3795
|
|
4
|
-
dapr/ext/fastapi/version.py,sha256=eYG8e0Uz0mlvNQDkrI6h7K21WOnyUFy2vbl5ChTd82U,618
|
|
5
|
-
dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/LICENSE,sha256=D-QjNdE9_ypCaJn2kkQy-AYHZZ_x5aozSpR7Q1CpbRs,11377
|
|
6
|
-
dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/METADATA,sha256=b4FjSvdRr987nlbVW2tEob143GuoTUyIwbyQqposfVM,1090
|
|
7
|
-
dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
8
|
-
dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/top_level.txt,sha256=iLDu9C_1nUTIsa3H4jMbuHuF-zs0opkitR7p7PCPYz0,5
|
|
9
|
-
dapr_ext_fastapi_dev-1.11.0rc1.dev1781.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|