jararaca 0.2.37a9__py3-none-any.whl → 0.2.37a11__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 jararaca might be problematic. Click here for more details.

jararaca/__init__.py CHANGED
@@ -59,6 +59,7 @@ if TYPE_CHECKING:
59
59
  from .messagebus.decorators import MessageBusController, MessageHandler
60
60
  from .messagebus.interceptors.aiopika_publisher_interceptor import (
61
61
  AIOPikaConnectionFactory,
62
+ GenericPoolConfig,
62
63
  MessageBusPublisherInterceptor,
63
64
  )
64
65
  from .messagebus.publisher import use_publisher
@@ -192,6 +193,7 @@ if TYPE_CHECKING:
192
193
  "Put",
193
194
  "Delete",
194
195
  "use_publisher",
196
+ "GenericPoolConfig",
195
197
  "AIOPikaConnectionFactory",
196
198
  "MessageBusPublisherInterceptor",
197
199
  "RedisWebSocketConnectionBackend",
@@ -221,6 +223,11 @@ _dynamic_imports: "dict[str, tuple[str, str, str | None]]" = {
221
223
  "messagebus.bus_message_controller",
222
224
  None,
223
225
  ),
226
+ "GenericPoolConfig": (
227
+ __SPEC_PARENT__,
228
+ "messagebus.interceptors.aiopika_publisher_interceptor",
229
+ None,
230
+ ),
224
231
  "ack": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
225
232
  "nack": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
226
233
  "reject": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
@@ -2,6 +2,7 @@ from contextlib import asynccontextmanager
2
2
  from typing import Any, AsyncContextManager, AsyncGenerator, Protocol
3
3
 
4
4
  import aio_pika
5
+ from aio_pika.abc import AbstractConnection
5
6
  from pydantic import BaseModel
6
7
 
7
8
  from jararaca.messagebus.publisher import MessagePublisher, provide_message_publisher
@@ -25,6 +26,10 @@ class MessageBusPublisherInterceptor(AppInterceptor):
25
26
 
26
27
  @asynccontextmanager
27
28
  async def intercept(self, app_context: AppContext) -> AsyncGenerator[None, None]:
29
+ if app_context.context_type == "websocket":
30
+ yield
31
+ return
32
+
28
33
  async with self.connection_factory.provide_connection() as connection:
29
34
  with provide_message_publisher(self.connection_name, connection):
30
35
  yield
@@ -48,29 +53,79 @@ class AIOPikaMessagePublisher(MessagePublisher):
48
53
  )
49
54
 
50
55
 
56
+ class GenericPoolConfig(BaseModel):
57
+ max_size: int
58
+
59
+
51
60
  class AIOPikaConnectionFactory(MessageBusConnectionFactory):
52
61
 
53
62
  def __init__(
54
63
  self,
55
64
  url: str,
56
65
  exchange: str,
66
+ connection_pool_config: GenericPoolConfig | None = None,
67
+ channel_pool_config: GenericPoolConfig | None = None,
57
68
  ):
58
69
  self.url = url
59
70
  self.exchange = exchange
60
71
 
72
+ self.connection_pool: aio_pika.pool.Pool[AbstractConnection] | None = None
73
+ self.channel_pool: aio_pika.pool.Pool[aio_pika.abc.AbstractChannel] | None = (
74
+ None
75
+ )
76
+
77
+ if connection_pool_config:
78
+
79
+ async def get_connection() -> AbstractConnection:
80
+ return await aio_pika.connect_robust(self.url)
81
+
82
+ self.connection_pool = aio_pika.pool.Pool[AbstractConnection](
83
+ get_connection,
84
+ max_size=connection_pool_config.max_size,
85
+ )
86
+
87
+ if channel_pool_config:
88
+
89
+ async def get_channel() -> aio_pika.abc.AbstractChannel:
90
+ async with self.acquire_connection() as connection:
91
+ return await connection.channel(publisher_confirms=False)
92
+
93
+ self.channel_pool = aio_pika.pool.Pool[aio_pika.abc.AbstractChannel](
94
+ get_channel, max_size=channel_pool_config.max_size
95
+ )
96
+
97
+ @asynccontextmanager
98
+ async def acquire_connection(self) -> AsyncGenerator[AbstractConnection, Any]:
99
+ if not self.connection_pool:
100
+ async with await aio_pika.connect_robust(self.url) as connection:
101
+ yield connection
102
+ else:
103
+
104
+ async with self.connection_pool.acquire() as connection:
105
+ yield connection
106
+
107
+ @asynccontextmanager
108
+ async def acquire_channel(
109
+ self,
110
+ ) -> AsyncGenerator[aio_pika.abc.AbstractChannel, Any]:
111
+ if not self.channel_pool:
112
+ async with self.acquire_connection() as connection:
113
+ yield await connection.channel(publisher_confirms=False)
114
+ else:
115
+ async with self.channel_pool.acquire() as channel:
116
+ yield channel
117
+
61
118
  @asynccontextmanager
62
119
  async def provide_connection(self) -> AsyncGenerator[AIOPikaMessagePublisher, Any]:
63
- connection = await aio_pika.connect_robust(self.url)
64
- async with connection:
65
- async with connection.channel(publisher_confirms=False) as channel:
66
120
 
67
- tx = channel.transaction()
121
+ async with self.acquire_channel() as channel:
122
+ tx = channel.transaction()
68
123
 
69
- await tx.select()
124
+ await tx.select()
70
125
 
71
- try:
72
- yield AIOPikaMessagePublisher(channel, exchange_name=self.exchange)
73
- await tx.commit()
74
- except Exception as e:
75
- await tx.rollback()
76
- raise e
126
+ try:
127
+ yield AIOPikaMessagePublisher(channel, exchange_name=self.exchange)
128
+ await tx.commit()
129
+ except Exception as e:
130
+ await tx.rollback()
131
+ raise e
@@ -1,5 +1,5 @@
1
1
  import inspect
2
- from typing import Any, Callable, Protocol, TypeVar, cast
2
+ from typing import Any, Callable, Literal, Protocol, TypeVar, cast
3
3
 
4
4
  from fastapi import APIRouter
5
5
  from fastapi import Depends as DependsF
@@ -147,6 +147,16 @@ class RestController:
147
147
 
148
148
  Options = dict[str, Any]
149
149
 
150
+ ResponseType = Literal[
151
+ "arraybuffer",
152
+ "blob",
153
+ "document",
154
+ "json",
155
+ "text",
156
+ "stream",
157
+ "formdata",
158
+ ]
159
+
150
160
 
151
161
  class HttpMapping:
152
162
 
@@ -154,11 +164,16 @@ class HttpMapping:
154
164
  ORDER_COUNTER = 0
155
165
 
156
166
  def __init__(
157
- self, method: str, path: str = "/", options: Options | None = None
167
+ self,
168
+ method: str,
169
+ path: str = "/",
170
+ adapter_options: Options | None = None,
171
+ response_type: ResponseType | None = None,
158
172
  ) -> None:
159
173
  self.method = method
160
174
  self.path = path
161
- self.options = options
175
+ self.options = adapter_options
176
+ self.response_type = response_type
162
177
 
163
178
  HttpMapping.ORDER_COUNTER += 1
164
179
  self.order = HttpMapping.ORDER_COUNTER
@@ -185,32 +200,57 @@ class HttpMapping:
185
200
 
186
201
  class Post(HttpMapping):
187
202
 
188
- def __init__(self, path: str = "/", options: Options | None = None) -> None:
189
- super().__init__("POST", path, options)
203
+ def __init__(
204
+ self,
205
+ path: str = "/",
206
+ options: Options | None = None,
207
+ response_type: ResponseType | None = None,
208
+ ) -> None:
209
+ super().__init__("POST", path, options, response_type)
190
210
 
191
211
 
192
212
  class Get(HttpMapping):
193
213
 
194
- def __init__(self, path: str = "/", options: Options | None = None) -> None:
195
- super().__init__("GET", path, options)
214
+ def __init__(
215
+ self,
216
+ path: str = "/",
217
+ options: Options | None = None,
218
+ response_type: ResponseType | None = None,
219
+ ) -> None:
220
+ super().__init__("GET", path, options, response_type)
196
221
 
197
222
 
198
223
  class Put(HttpMapping):
199
224
 
200
- def __init__(self, path: str = "/", options: Options | None = None) -> None:
201
- super().__init__("PUT", path, options)
225
+ def __init__(
226
+ self,
227
+ path: str = "/",
228
+ options: Options | None = None,
229
+ response_type: ResponseType | None = None,
230
+ ) -> None:
231
+ super().__init__("PUT", path, options, response_type)
202
232
 
203
233
 
204
234
  class Delete(HttpMapping):
205
235
 
206
- def __init__(self, path: str = "/", options: Options | None = None) -> None:
207
- super().__init__("DELETE", path, options)
236
+ def __init__(
237
+ self,
238
+ path: str = "/",
239
+ options: Options | None = None,
240
+ response_type: ResponseType | None = None,
241
+ ) -> None:
242
+ super().__init__("DELETE", path, options, response_type)
208
243
 
209
244
 
210
245
  class Patch(HttpMapping):
211
246
 
212
- def __init__(self, path: str = "/", options: Options | None = None) -> None:
213
- super().__init__("PATCH", path, options)
247
+ def __init__(
248
+ self,
249
+ path: str = "/",
250
+ options: Options | None = None,
251
+ response_type: ResponseType | None = None,
252
+ ) -> None:
253
+ super().__init__("PATCH", path, options, response_type)
214
254
 
215
255
 
216
256
  class UseMiddleware:
@@ -85,6 +85,8 @@ def parse_literal_value(value: Any) -> str:
85
85
 
86
86
 
87
87
  def get_field_type_for_ts(field_type: Any) -> Any:
88
+ if field_type is Response:
89
+ return "unknown"
88
90
  if field_type is Any:
89
91
  return "any"
90
92
  if field_type == UploadFile:
@@ -367,12 +369,23 @@ export type WebSocketMessageMap = {
367
369
 
368
370
  final_buffer.write(
369
371
  """
372
+ export type ResponseType =
373
+ | "arraybuffer"
374
+ | "blob"
375
+ | "document"
376
+ | "json"
377
+ | "text"
378
+ | "stream"
379
+ | "formdata";
380
+
381
+
370
382
  export interface HttpBackendRequest {
371
383
  method: string;
372
384
  path: string;
373
385
  headers: { [key: string]: string };
374
386
  query: { [key: string]: unknown };
375
387
  body: unknown;
388
+ responseType?: ResponseType;
376
389
  }
377
390
 
378
391
  export interface HttpBackend {
@@ -491,6 +504,8 @@ def write_rest_controller_to_typescript_interface(
491
504
  "const response = await this.httpBackend.request<%s>({ \n"
492
505
  % return_value_repr
493
506
  )
507
+ if mapping.response_type is not None:
508
+ class_buffer.write(f'\t\t\tresponseType: "{mapping.response_type}",\n')
494
509
  class_buffer.write(f'\t\t\tmethod: "{mapping.method}",\n')
495
510
 
496
511
  endpoint_path = parse_path_with_params(mapping.path, arg_params_spec)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jararaca
3
- Version: 0.2.37a9
3
+ Version: 0.2.37a11
4
4
  Summary: A simple and fast API framework for Python
5
5
  Home-page: https://github.com/LuscasLeo/jararaca
6
6
  Author: Lucas S
@@ -1,7 +1,7 @@
1
1
  LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
2
2
  README.md,sha256=mte30I-ZEJJp-Oax-OganNgl6G9GaCZPL6JVFAvZGz4,7034
3
- pyproject.toml,sha256=2UOhWHtsEocbNG2dLDU2dLKDKluERP8cFYHdnh8L990,1839
4
- jararaca/__init__.py,sha256=gDCvrIhIu5_IkKjmZmhWZ2khOi8WGiw2AidFFe-BnWU,15118
3
+ pyproject.toml,sha256=6qmtrXrdw7bJZOL_-RGgWJtkCmz7b42Xbc-NwubeGTQ,1840
4
+ jararaca/__init__.py,sha256=VBrN25GHJ3gDG95CcJWe3dmGcA-X2agzOCIBbjzc1Iw,15312
5
5
  jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
6
6
  jararaca/cli.py,sha256=JKk4xrRbtX2fM8yYw794lbxvJFH73bWw3GGIvrpAkeE,5706
7
7
  jararaca/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -15,7 +15,7 @@ jararaca/messagebus/__init__.py,sha256=Zdl74HcS9K0FW6XUt7bVvaHEyxL8pWsqqakeRENIn
15
15
  jararaca/messagebus/bus_message_controller.py,sha256=Xd_qwnX5jUvgBTCarHR36fvtol9lPTsYp2IIGKyQQaE,1487
16
16
  jararaca/messagebus/decorators.py,sha256=GHlaXRuHtrz6R0HgcG2gJybpGYtdts9meDVSRPwN74I,4245
17
17
  jararaca/messagebus/interceptors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- jararaca/messagebus/interceptors/aiopika_publisher_interceptor.py,sha256=rqAX644-VHarg6kPPsXGTmxYd79PpJXiJ1N1gIooJTo,2470
18
+ jararaca/messagebus/interceptors/aiopika_publisher_interceptor.py,sha256=BPH5wOlj_CyHtJ7W4NWF2h0gYMwzOPNzFhGADk618N4,4373
19
19
  jararaca/messagebus/publisher.py,sha256=5ay9Znwybqt981OOykdWkFisSvGiTeTpPXDFLMnaiqg,1109
20
20
  jararaca/messagebus/types.py,sha256=iYLyLxWqOHkDadxyMqQPWy3itLNQfvD6oQe8jcq9nzo,887
21
21
  jararaca/messagebus/worker.py,sha256=hKACTyrIMHcuaySpmI3UhDCja6va1gGkFRoZJ7kYfoA,13613
@@ -32,7 +32,7 @@ jararaca/persistence/session.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
32
32
  jararaca/persistence/sort_filter.py,sha256=agggpN0YvNjUr6wJjy69NkaqxoDDW13ys9B3r85OujA,9226
33
33
  jararaca/persistence/utilities.py,sha256=0v1YrK-toTCgtw8aROtrDMNfjo3qWWNAb5qQcCOdSUU,13681
34
34
  jararaca/presentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- jararaca/presentation/decorators.py,sha256=eL2YCgMSr19m4YCri5PQU46NRxf0QxsqDnz6MqKu0YQ,8389
35
+ jararaca/presentation/decorators.py,sha256=EErRZtLZDoZZj1ZVlDkGQbvqpoQkBaoU70KAUwWIufs,9146
36
36
  jararaca/presentation/hooks.py,sha256=WBbU5DG3-MAm2Ro2YraQyYG_HENfizYfyShL2ktHi6k,1980
37
37
  jararaca/presentation/http_microservice.py,sha256=g771JosV6jTY3hQtG-HkLOo-T0e-r3b3rp1ddt99Qf0,533
38
38
  jararaca/presentation/server.py,sha256=JuEatLFhD_NFnszwXDSgtcCXNOwvQYyxoxxQ33hnAEc,3731
@@ -58,9 +58,9 @@ jararaca/tools/app_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
58
58
  jararaca/tools/app_config/decorators.py,sha256=-ckkMZ1dswOmECdo1rFrZ15UAku--txaNXMp8fd1Ndk,941
59
59
  jararaca/tools/app_config/interceptor.py,sha256=nfFZiS80hrbnL7-XEYrwmp2rwaVYBqxvqu3Y-6o_ov4,2575
60
60
  jararaca/tools/metadata.py,sha256=7nlCDYgItNybentPSSCc2MLqN7IpBd0VyQzfjfQycVI,1402
61
- jararaca/tools/typescript/interface_parser.py,sha256=l-QyPVntATcbL4JYm48xq2gNWfV1y2iArvOuIueFi8w,28829
62
- jararaca-0.2.37a9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
63
- jararaca-0.2.37a9.dist-info/METADATA,sha256=RkVCVzBHDnAGBl11qdhtmRoYnQcE4AOEKrF6I0Oip3U,8554
64
- jararaca-0.2.37a9.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
65
- jararaca-0.2.37a9.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
66
- jararaca-0.2.37a9.dist-info/RECORD,,
61
+ jararaca/tools/typescript/interface_parser.py,sha256=4SHt094P-QawMFHSyMCiujQf8Niw7xACIO1RHBM8-w4,29192
62
+ jararaca-0.2.37a11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
63
+ jararaca-0.2.37a11.dist-info/METADATA,sha256=o0sSsRaTx6-ySotULbIhDQtza302CTjxCc9jdAJxbJ8,8555
64
+ jararaca-0.2.37a11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
65
+ jararaca-0.2.37a11.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
66
+ jararaca-0.2.37a11.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "jararaca"
3
- version = "0.2.37a9"
3
+ version = "0.2.37a11"
4
4
  description = "A simple and fast API framework for Python"
5
5
  authors = ["Lucas S <me@luscasleo.dev>"]
6
6
  readme = "README.md"