ul-api-utils 7.11.0__py3-none-any.whl → 7.11.2__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 ul-api-utils might be problematic. Click here for more details.
- example/redis_repository.py +22 -0
- example/routes/api_some.py +5 -0
- ul_api_utils/modules/api_sdk.py +1 -0
- ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_three_specifier.py +1 -1
- ul_api_utils/utils/memory_db/repository.py +7 -1
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/METADATA +1 -1
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/RECORD +11 -10
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/LICENSE +0 -0
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/WHEEL +0 -0
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/entry_points.txt +0 -0
- {ul_api_utils-7.11.0.dist-info → ul_api_utils-7.11.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import redis
|
|
4
|
+
from pydantic import BaseModel, UUID4
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
from ul_api_utils.utils.memory_db.repository import BaseMemoryDbRepository
|
|
7
|
+
|
|
8
|
+
redis_client: Any = redis.StrictRedis.from_url("redis://172.19.0.2:6379")
|
|
9
|
+
redis_db = BaseMemoryDbRepository(redis_client=redis_client)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Person(BaseModel):
|
|
13
|
+
id: UUID4
|
|
14
|
+
name: str = 'Slava'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
slava = Person(id=uuid4())
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
redis_db['slava'] = 35
|
|
21
|
+
value = redis_db['slava', Person]
|
|
22
|
+
value2 = redis_db.get('slava', default=1)
|
example/routes/api_some.py
CHANGED
|
@@ -48,15 +48,18 @@ class Eeenum(IntEnum):
|
|
|
48
48
|
one = 1
|
|
49
49
|
two = 2
|
|
50
50
|
|
|
51
|
+
|
|
51
52
|
class SomeBody(BaseModel):
|
|
52
53
|
seconds: float
|
|
53
54
|
eenum: Optional[Eeenum]
|
|
54
55
|
|
|
56
|
+
|
|
55
57
|
class Some2Query(ApiRequestQuery):
|
|
56
58
|
sleep: float = 0.4
|
|
57
59
|
some: QueryParamsSeparatedList[str] = '' # type: ignore
|
|
58
60
|
eenum: Optional[Eeenum]
|
|
59
61
|
|
|
62
|
+
|
|
60
63
|
logger = logging.getLogger(__name__)
|
|
61
64
|
|
|
62
65
|
|
|
@@ -83,10 +86,12 @@ def some5(api_resource: ApiResource, body: SomeBody) -> JsonApiResponse[List[Res
|
|
|
83
86
|
RespObject(now=datetime.now() + timedelta(seconds=body.seconds * 2)),
|
|
84
87
|
], 2)
|
|
85
88
|
|
|
89
|
+
|
|
86
90
|
class Eennum(Enum):
|
|
87
91
|
one = 'one'
|
|
88
92
|
two = 'two'
|
|
89
93
|
|
|
94
|
+
|
|
90
95
|
class Some7Query(ApiRequestQuery):
|
|
91
96
|
need_redirect: int
|
|
92
97
|
eenum: Optional[Eeenum]
|
ul_api_utils/modules/api_sdk.py
CHANGED
|
@@ -258,6 +258,7 @@ class ApiSdk:
|
|
|
258
258
|
assert self._sio # mypy
|
|
259
259
|
self._sio.init_app(
|
|
260
260
|
flask_app,
|
|
261
|
+
json=flask_app.json_encoder,
|
|
261
262
|
message_queue=self._config.socket_config.message_queue,
|
|
262
263
|
async_mode=SocketAsyncModesEnum.GEVENT.value,
|
|
263
264
|
channel=self._config.socket_config.channel,
|
|
@@ -378,7 +378,7 @@ class SwaggerQueryParameter(SwaggerModel):
|
|
|
378
378
|
name: Optional[str] = None,
|
|
379
379
|
description: Optional[str] = None,
|
|
380
380
|
required: bool = True,
|
|
381
|
-
enum: Optional[list] = None,
|
|
381
|
+
enum: Optional[list] = None, # type: ignore
|
|
382
382
|
) -> None:
|
|
383
383
|
super(SwaggerQueryParameter, self).__init__()
|
|
384
384
|
self.input_type = InputType.from_string(input_type) # type: ignore
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import decimal
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
|
|
2
4
|
import redis
|
|
3
5
|
import ormsgpack
|
|
4
6
|
import collections
|
|
@@ -13,6 +15,7 @@ CompositeKeyT = tuple[str, Type[BaseModel]]
|
|
|
13
15
|
AnyKeyT = str | CompositeKeyT
|
|
14
16
|
AnyT = Any
|
|
15
17
|
RedisClientT = redis.StrictRedis | redis.Redis
|
|
18
|
+
ExpiryT = int | timedelta | None
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
class BaseMemoryDbRepository(collections.abc.MutableMapping[str, AnyT]):
|
|
@@ -32,6 +35,10 @@ class BaseMemoryDbRepository(collections.abc.MutableMapping[str, AnyT]):
|
|
|
32
35
|
except KeyError:
|
|
33
36
|
return default
|
|
34
37
|
|
|
38
|
+
def set(self, __key: str, value: AnyT, *, expires: ExpiryT = None) -> None:
|
|
39
|
+
packed_value = ormsgpack.packb(value, option=ormsgpack.OPT_SERIALIZE_PYDANTIC, default=self._default_serializer)
|
|
40
|
+
self._db.set(__key, packed_value, ex=expires)
|
|
41
|
+
|
|
35
42
|
@overload
|
|
36
43
|
def __getitem__(self, key: str) -> AnyT:
|
|
37
44
|
...
|
|
@@ -48,7 +55,6 @@ class BaseMemoryDbRepository(collections.abc.MutableMapping[str, AnyT]):
|
|
|
48
55
|
return ormsgpack.unpackb(self._db[single_key])
|
|
49
56
|
|
|
50
57
|
composite_key = cast(CompositeKeyT, key)
|
|
51
|
-
|
|
52
58
|
if len(composite_key) > self._composite_key_max_length:
|
|
53
59
|
raise CompositeKeyError(f"Can't retrieve an item with {key=}. Composite key should have only two arguments.")
|
|
54
60
|
|
|
@@ -4,9 +4,10 @@ example/main.py,sha256=GtesHWpYeYbkBfkex0ZM2ma704NTT3ZwGF2Nzs_8I0E,543
|
|
|
4
4
|
example/permissions.py,sha256=i8_zOOPdra3oMXZfyTspewRYNdn21PCqOD1ATG69Itk,277
|
|
5
5
|
example/pure_flask_example.py,sha256=A7cbcjTr28FS1sVNAsQbj1N9EgEFIXDB4aRwOV6_tbU,1329
|
|
6
6
|
example/rate_limit_load.py,sha256=U2Bgp8UztT4TNKdv9NVioxWfE68aCsC7uKz7xPCy6XM,225
|
|
7
|
+
example/redis_repository.py,sha256=ew9Ixdn0rAAE5iUINdxLJ9BdbhoD09FJzigdc7cNFAc,504
|
|
7
8
|
example/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
9
|
example/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
example/routes/api_some.py,sha256=
|
|
10
|
+
example/routes/api_some.py,sha256=rjguCsuDH8XpuM1gUcIe2dSbUnACR0sh-z6zQHBH0cM,13037
|
|
10
11
|
example/sockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
12
|
example/sockets/on_connect.py,sha256=3sluHnVT_-e2Oa4YsRZUJIc2L4VnMSJu5rgI_mkg8BQ,411
|
|
12
13
|
example/sockets/on_disconnect.py,sha256=ev0uJutqmTSsbrBcQIRudBX-6g7uSmZj8Imuf6pVIMU,277
|
|
@@ -63,7 +64,7 @@ ul_api_utils/internal_api/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
|
|
|
63
64
|
ul_api_utils/internal_api/__tests__/internal_api.py,sha256=X2iopeso6vryszeeA__lcqXQVtz3Nwt3ngH7M4OuN1U,1116
|
|
64
65
|
ul_api_utils/internal_api/__tests__/internal_api_content_type.py,sha256=mfiYPkzKtfZKFpi4RSnWAoCd6mRijr6sFsa2TF-s5t8,749
|
|
65
66
|
ul_api_utils/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
|
-
ul_api_utils/modules/api_sdk.py,sha256=
|
|
67
|
+
ul_api_utils/modules/api_sdk.py,sha256=bREHqbM-kYstw5xFfoFR6TC0407aq57nbYOm9rpTF7o,26484
|
|
67
68
|
ul_api_utils/modules/api_sdk_config.py,sha256=3r46W5jNKlx7K2MWP94QuM216fmQkhP6LtCRZ9KmNEs,2151
|
|
68
69
|
ul_api_utils/modules/api_sdk_jwt.py,sha256=2XRfb0LxHUnldSL67S60v1uyoDpVPNaq4zofUtkeg88,15112
|
|
69
70
|
ul_api_utils/modules/intermediate_state.py,sha256=7ZZ3Sypbb8LaSfrVhaXaWRDnj8oyy26NUbmFK7vr-y4,1270
|
|
@@ -124,7 +125,7 @@ ul_api_utils/utils/flask_swagger_generator/exceptions.py,sha256=yA4IsUyxh5puyoYz
|
|
|
124
125
|
ul_api_utils/utils/flask_swagger_generator/specifiers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
125
126
|
ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_models.py,sha256=eMRDP60GUbIuBGinFPfjp7VsnbgmzockTsIT-KadchA,1690
|
|
126
127
|
ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_specifier.py,sha256=9Cf1ijk90IDYUDG8kTjK4cxjdxpYjWZz1tKJHPCeDAA,1513
|
|
127
|
-
ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_three_specifier.py,sha256=
|
|
128
|
+
ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_three_specifier.py,sha256=ReG74_qMT8yVLJAIDZBwcWRxWgACaEgmfxzc0p5dmyY,30828
|
|
128
129
|
ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_version.py,sha256=A14IRG-e2KL2SlFbHep2FH0uMRIHPhfd7KLkYdtWrfA,1312
|
|
129
130
|
ul_api_utils/utils/flask_swagger_generator/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
130
131
|
ul_api_utils/utils/flask_swagger_generator/utils/input_type.py,sha256=Ynp3zI5q1F0Tl_eTdNbWoCxRKPwBCJkwJOoeHE2pTRE,2533
|
|
@@ -138,7 +139,7 @@ ul_api_utils/utils/jinja/t_url_for.py,sha256=PG9W4UbkWv2pLXNMQiCt22vp4sDi-Uz5w2u
|
|
|
138
139
|
ul_api_utils/utils/jinja/to_pretty_json.py,sha256=wcc_EJ6yM4lipE0Vr6cgYOB-rBk7_j_Wa7bijjI_bCs,302
|
|
139
140
|
ul_api_utils/utils/memory_db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
140
141
|
ul_api_utils/utils/memory_db/errors.py,sha256=Bw1O1Y_WTCeCRNgb9iwrGT1fst6iHORhrNstwxiaUu8,267
|
|
141
|
-
ul_api_utils/utils/memory_db/repository.py,sha256=
|
|
142
|
+
ul_api_utils/utils/memory_db/repository.py,sha256=FDauZgcYiQWn-yYGCMsvaT4C2CES8WG2iSwcpVmmXu4,3715
|
|
142
143
|
ul_api_utils/utils/memory_db/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
143
144
|
ul_api_utils/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
144
145
|
ul_api_utils/validators/custom_fields.py,sha256=iqDnAvO-Bs13ZtLtccAG8SdJ8jWDlVcW6_ckChrTdXQ,4023
|
|
@@ -146,9 +147,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
|
|
|
146
147
|
ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
|
|
147
148
|
ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
148
149
|
ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=QLZ7DFta01Z7DOK9Z5Iq4uf_CmvDkVReis-GAl_QN48,1447
|
|
149
|
-
ul_api_utils-7.11.
|
|
150
|
-
ul_api_utils-7.11.
|
|
151
|
-
ul_api_utils-7.11.
|
|
152
|
-
ul_api_utils-7.11.
|
|
153
|
-
ul_api_utils-7.11.
|
|
154
|
-
ul_api_utils-7.11.
|
|
150
|
+
ul_api_utils-7.11.2.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
|
|
151
|
+
ul_api_utils-7.11.2.dist-info/METADATA,sha256=wgtiiTwRPfwS3HXLpyRpXsACEEcRFCcEaaaPjV0J1aQ,14715
|
|
152
|
+
ul_api_utils-7.11.2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
153
|
+
ul_api_utils-7.11.2.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
|
|
154
|
+
ul_api_utils-7.11.2.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
|
|
155
|
+
ul_api_utils-7.11.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|