fastapi-rtk 0.2.27__py3-none-any.whl → 1.0.13__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.
Files changed (98) hide show
  1. fastapi_rtk/__init__.py +39 -35
  2. fastapi_rtk/_version.py +1 -0
  3. fastapi_rtk/api/model_rest_api.py +476 -221
  4. fastapi_rtk/auth/auth.py +0 -9
  5. fastapi_rtk/backends/generic/__init__.py +6 -0
  6. fastapi_rtk/backends/generic/column.py +21 -12
  7. fastapi_rtk/backends/generic/db.py +42 -7
  8. fastapi_rtk/backends/generic/filters.py +21 -16
  9. fastapi_rtk/backends/generic/interface.py +14 -8
  10. fastapi_rtk/backends/generic/model.py +19 -11
  11. fastapi_rtk/backends/sqla/__init__.py +1 -0
  12. fastapi_rtk/backends/sqla/db.py +77 -17
  13. fastapi_rtk/backends/sqla/extensions/audit/audit.py +401 -189
  14. fastapi_rtk/backends/sqla/extensions/geoalchemy2/filters.py +15 -12
  15. fastapi_rtk/backends/sqla/filters.py +50 -21
  16. fastapi_rtk/backends/sqla/interface.py +96 -34
  17. fastapi_rtk/backends/sqla/model.py +56 -39
  18. fastapi_rtk/bases/__init__.py +20 -0
  19. fastapi_rtk/bases/db.py +94 -7
  20. fastapi_rtk/bases/file_manager.py +47 -3
  21. fastapi_rtk/bases/filter.py +22 -0
  22. fastapi_rtk/bases/interface.py +49 -5
  23. fastapi_rtk/bases/model.py +3 -0
  24. fastapi_rtk/bases/session.py +2 -0
  25. fastapi_rtk/cli/cli.py +62 -9
  26. fastapi_rtk/cli/commands/__init__.py +23 -0
  27. fastapi_rtk/cli/{db.py → commands/db/__init__.py} +107 -50
  28. fastapi_rtk/cli/{templates → commands/db/templates}/fastapi/env.py +2 -3
  29. fastapi_rtk/cli/{templates → commands/db/templates}/fastapi-multidb/env.py +10 -9
  30. fastapi_rtk/cli/{templates → commands/db/templates}/fastapi-multidb/script.py.mako +3 -1
  31. fastapi_rtk/cli/{export.py → commands/export.py} +12 -10
  32. fastapi_rtk/cli/{security.py → commands/security.py} +73 -7
  33. fastapi_rtk/cli/commands/translate.py +299 -0
  34. fastapi_rtk/cli/decorators.py +9 -4
  35. fastapi_rtk/cli/utils.py +46 -0
  36. fastapi_rtk/config.py +41 -1
  37. fastapi_rtk/const.py +29 -1
  38. fastapi_rtk/db.py +76 -40
  39. fastapi_rtk/decorators.py +1 -1
  40. fastapi_rtk/dependencies.py +134 -62
  41. fastapi_rtk/exceptions.py +51 -1
  42. fastapi_rtk/fastapi_react_toolkit.py +186 -171
  43. fastapi_rtk/file_managers/file_manager.py +8 -6
  44. fastapi_rtk/file_managers/s3_file_manager.py +69 -33
  45. fastapi_rtk/globals.py +22 -12
  46. fastapi_rtk/lang/__init__.py +3 -0
  47. fastapi_rtk/lang/babel/__init__.py +4 -0
  48. fastapi_rtk/lang/babel/cli.py +40 -0
  49. fastapi_rtk/lang/babel/config.py +17 -0
  50. fastapi_rtk/lang/babel.cfg +1 -0
  51. fastapi_rtk/lang/lazy_text.py +120 -0
  52. fastapi_rtk/lang/messages.pot +238 -0
  53. fastapi_rtk/lang/translations/de/LC_MESSAGES/messages.mo +0 -0
  54. fastapi_rtk/lang/translations/de/LC_MESSAGES/messages.po +248 -0
  55. fastapi_rtk/lang/translations/en/LC_MESSAGES/messages.mo +0 -0
  56. fastapi_rtk/lang/translations/en/LC_MESSAGES/messages.po +244 -0
  57. fastapi_rtk/manager.py +355 -37
  58. fastapi_rtk/mixins.py +12 -0
  59. fastapi_rtk/routers.py +208 -72
  60. fastapi_rtk/schemas.py +142 -39
  61. fastapi_rtk/security/sqla/apis.py +39 -13
  62. fastapi_rtk/security/sqla/models.py +8 -23
  63. fastapi_rtk/security/sqla/security_manager.py +369 -11
  64. fastapi_rtk/setting.py +446 -88
  65. fastapi_rtk/types.py +94 -27
  66. fastapi_rtk/utils/__init__.py +8 -0
  67. fastapi_rtk/utils/async_task_runner.py +286 -61
  68. fastapi_rtk/utils/csv_json_converter.py +243 -40
  69. fastapi_rtk/utils/hooks.py +34 -0
  70. fastapi_rtk/utils/merge_schema.py +3 -3
  71. fastapi_rtk/utils/multiple_async_contexts.py +21 -0
  72. fastapi_rtk/utils/pydantic.py +46 -1
  73. fastapi_rtk/utils/run_utils.py +31 -1
  74. fastapi_rtk/utils/self_dependencies.py +1 -1
  75. fastapi_rtk/utils/use_default_when_none.py +1 -1
  76. fastapi_rtk/version.py +6 -1
  77. fastapi_rtk-1.0.13.dist-info/METADATA +28 -0
  78. fastapi_rtk-1.0.13.dist-info/RECORD +133 -0
  79. {fastapi_rtk-0.2.27.dist-info → fastapi_rtk-1.0.13.dist-info}/WHEEL +1 -2
  80. fastapi_rtk/backends/gremlinpython/__init__.py +0 -108
  81. fastapi_rtk/backends/gremlinpython/column.py +0 -208
  82. fastapi_rtk/backends/gremlinpython/db.py +0 -228
  83. fastapi_rtk/backends/gremlinpython/exceptions.py +0 -34
  84. fastapi_rtk/backends/gremlinpython/filters.py +0 -461
  85. fastapi_rtk/backends/gremlinpython/interface.py +0 -734
  86. fastapi_rtk/backends/gremlinpython/model.py +0 -364
  87. fastapi_rtk/backends/gremlinpython/session.py +0 -23
  88. fastapi_rtk/cli/commands.py +0 -295
  89. fastapi_rtk-0.2.27.dist-info/METADATA +0 -23
  90. fastapi_rtk-0.2.27.dist-info/RECORD +0 -126
  91. fastapi_rtk-0.2.27.dist-info/top_level.txt +0 -1
  92. /fastapi_rtk/cli/{templates → commands/db/templates}/fastapi/README +0 -0
  93. /fastapi_rtk/cli/{templates → commands/db/templates}/fastapi/alembic.ini.mako +0 -0
  94. /fastapi_rtk/cli/{templates → commands/db/templates}/fastapi/script.py.mako +0 -0
  95. /fastapi_rtk/cli/{templates → commands/db/templates}/fastapi-multidb/README +0 -0
  96. /fastapi_rtk/cli/{templates → commands/db/templates}/fastapi-multidb/alembic.ini.mako +0 -0
  97. {fastapi_rtk-0.2.27.dist-info → fastapi_rtk-1.0.13.dist-info}/entry_points.txt +0 -0
  98. {fastapi_rtk-0.2.27.dist-info → fastapi_rtk-1.0.13.dist-info}/licenses/LICENSE +0 -0
@@ -1,461 +0,0 @@
1
- import datetime
2
- import typing
3
-
4
- import gremlin_python.process.graph_traversal
5
- import gremlin_python.process.traversal
6
-
7
- from ...const import logger
8
-
9
- try:
10
- import janusgraph_python.process.traversal
11
- except ImportError:
12
- logger.warning(
13
- "janusgraph_python is not installed. Some Gremlin features may not work as expected."
14
- )
15
- janusgraph_python = None
16
-
17
- from ...bases.filter import AbstractBaseFilter
18
-
19
- if typing.TYPE_CHECKING:
20
- from .interface import GremlinInterface
21
-
22
- __all__ = [
23
- "GremlinBaseFilter",
24
- "GremlinBaseFilterRelationOneToOneOrManyToOne",
25
- "GremlinBaseFilterRelationOneToManyOrManyToMany",
26
- "GremlinFilterTextContains",
27
- "GremlinFilterEqual",
28
- "GremlinFilterNotEqual",
29
- "GremlinFilterStartsWith",
30
- "GremlinFilterNotStartsWith",
31
- "GremlinFilterEndsWith",
32
- "GremlinFilterNotEndsWith",
33
- "GremlinFilterContains",
34
- "GremlinFilterNotContains",
35
- "GremlinFilterGreater",
36
- "GremlinFilterSmaller",
37
- "GremlinFilterGreaterEqual",
38
- "GremlinFilterSmallerEqual",
39
- "GremlinFilterIn",
40
- "GremlinFilterBetween",
41
- "GremlinFilterRelationOneToOneOrManyToOneEqual",
42
- "GremlinFilterRelationOneToManyOrManyToManyIn",
43
- "GremlinFilterConverter",
44
- ]
45
-
46
-
47
- class GremlinBaseFilter(
48
- AbstractBaseFilter[gremlin_python.process.graph_traversal.GraphTraversal]
49
- ):
50
- datamodel: "GremlinInterface"
51
-
52
- def _apply(
53
- self,
54
- statement: gremlin_python.process.graph_traversal.GraphTraversal,
55
- col: str,
56
- args: tuple[str, typing.Any],
57
- ):
58
- func = statement.has
59
- if col.lower() == self.datamodel.obj.__mapper__.pk:
60
- func = statement.hasId
61
- args = args[1:]
62
- elif col.lower() == self.datamodel.obj.__mapper__.lk:
63
- func = statement.hasLabel
64
- args = args[1:]
65
- return func(*args)
66
-
67
-
68
- class GremlinBaseFilterRelationOneToOneOrManyToOne(GremlinBaseFilter):
69
- def _rel_apply(self, col: str, value: str):
70
- match self.datamodel.list_properties[col].direction:
71
- case "both":
72
- statement = gremlin_python.process.graph_traversal.__.bothE()
73
- case "in":
74
- statement = gremlin_python.process.graph_traversal.__.inE()
75
- case "out":
76
- statement = gremlin_python.process.graph_traversal.__.outE()
77
- case _:
78
- raise ValueError(
79
- f"Invalid direction for relation: {col}, must be 'both', 'in' or 'out'."
80
- )
81
- if self.datamodel.list_properties[col].properties:
82
- for key, val in self.datamodel.list_properties[col].properties.items():
83
- statement = statement.has(key, val)
84
- statement = statement.otherV()
85
- if self.datamodel.list_properties[col].obj_properties:
86
- for key, val in self.datamodel.list_properties[col].obj_properties.items():
87
- statement = statement.has(key, val)
88
- return statement.hasId(value)
89
-
90
-
91
- class GremlinBaseFilterRelationOneToManyOrManyToMany(
92
- GremlinBaseFilterRelationOneToOneOrManyToOne
93
- ):
94
- def _rel_apply(self, col, value: list[str]):
95
- return [super()._rel_apply(col, v) for v in value] if value else []
96
-
97
-
98
- class GremlinFilterTextContains(GremlinBaseFilter):
99
- name = "Text contains"
100
- arg_name = "tc"
101
-
102
- def apply(self, statement, col, value):
103
- value_func = (
104
- janusgraph_python.process.traversal.Text.text_contains
105
- if janusgraph_python
106
- else gremlin_python.process.traversal.TextP.containing
107
- )
108
-
109
- statement = self._apply(statement, col, (col, value_func(value)))
110
- if janusgraph_python:
111
- statement = statement.fold().unfold()
112
- return statement
113
-
114
-
115
- class GremlinFilterEqual(GremlinBaseFilter):
116
- name = "Equal to"
117
- arg_name = "eq"
118
-
119
- def apply(self, statement, col, value):
120
- return self._apply(statement, col, [col, value])
121
-
122
-
123
- class GremlinFilterNotEqual(GremlinBaseFilter):
124
- name = "Not equal to"
125
- arg_name = "neq"
126
-
127
- def apply(self, statement, col, value):
128
- return self._apply(
129
- statement, col, [col, gremlin_python.process.traversal.P.neq(value)]
130
- )
131
-
132
-
133
- class GremlinFilterStartsWith(GremlinBaseFilter):
134
- name = "Starts with"
135
- arg_name = "sw"
136
-
137
- def apply(self, statement, col, value):
138
- return self._apply(
139
- statement,
140
- col,
141
- (col, gremlin_python.process.traversal.TextP.startingWith(value)),
142
- )
143
-
144
-
145
- class GremlinFilterNotStartsWith(GremlinBaseFilter):
146
- name = "Not starts with"
147
- arg_name = "nsw"
148
-
149
- def apply(self, statement, col, value):
150
- return self._apply(
151
- statement,
152
- col,
153
- (col, gremlin_python.process.traversal.TextP.notStartingWith(value)),
154
- )
155
-
156
-
157
- class GremlinFilterEndsWith(GremlinBaseFilter):
158
- name = "Ends with"
159
- arg_name = "ew"
160
-
161
- def apply(self, statement, col, value):
162
- return self._apply(
163
- statement,
164
- col,
165
- (col, gremlin_python.process.traversal.TextP.endingWith(value)),
166
- )
167
-
168
-
169
- class GremlinFilterNotEndsWith(GremlinBaseFilter):
170
- name = "Not ends with"
171
- arg_name = "new"
172
-
173
- def apply(self, statement, col, value):
174
- return self._apply(
175
- statement,
176
- col,
177
- (col, gremlin_python.process.traversal.TextP.notEndingWith(value)),
178
- )
179
-
180
-
181
- class GremlinFilterContains(GremlinBaseFilter):
182
- name = "Contains"
183
- arg_name = "ct"
184
-
185
- def apply(self, statement, col, value):
186
- value_func = (
187
- janusgraph_python.process.traversal.Text.text_contains
188
- if janusgraph_python
189
- else gremlin_python.process.traversal.TextP.containing
190
- )
191
-
192
- statement = self._apply(statement, col, (col, value_func(value)))
193
- if janusgraph_python:
194
- statement = statement.fold().unfold()
195
- return statement
196
-
197
-
198
- class GremlinFilterNotContains(GremlinBaseFilter):
199
- name = "Not contains"
200
- arg_name = "nct"
201
-
202
- def apply(self, statement, col, value):
203
- value_func = (
204
- janusgraph_python.process.traversal.Text.text_not_contains
205
- if janusgraph_python
206
- else gremlin_python.process.traversal.TextP.notContaining
207
- )
208
-
209
- return self._apply(statement, col, (col, value_func(value)))
210
-
211
-
212
- class GremlinFilterGreater(GremlinBaseFilter):
213
- name = "Greater than"
214
- arg_name = "gt"
215
-
216
- def apply(self, statement, col, value):
217
- if isinstance(value, datetime.datetime):
218
- value = value.timestamp()
219
- elif isinstance(value, datetime.date):
220
- value = datetime.datetime.combine(value, datetime.datetime.min.time())
221
-
222
- return self._apply(
223
- statement, col, (col, gremlin_python.process.traversal.P.gt(value))
224
- )
225
-
226
-
227
- class GremlinFilterSmaller(GremlinBaseFilter):
228
- name = "Smaller than"
229
- arg_name = "sm"
230
-
231
- def apply(self, statement, col, value):
232
- if isinstance(value, datetime.datetime):
233
- value = value.timestamp()
234
- elif isinstance(value, datetime.date):
235
- value = datetime.datetime.combine(value, datetime.datetime.min.time())
236
-
237
- return self._apply(
238
- statement, col, (col, gremlin_python.process.traversal.P.lt(value))
239
- )
240
-
241
-
242
- class GremlinFilterGreaterEqual(GremlinBaseFilter):
243
- name = "Greater equal"
244
- arg_name = "gte"
245
-
246
- def apply(self, statement, col, value):
247
- if isinstance(value, datetime.datetime):
248
- value = value.timestamp()
249
- elif isinstance(value, datetime.date):
250
- value = datetime.datetime.combine(value, datetime.datetime.min.time())
251
-
252
- return self._apply(
253
- statement, col, (col, gremlin_python.process.traversal.P.gte(value))
254
- )
255
-
256
-
257
- class GremlinFilterSmallerEqual(GremlinBaseFilter):
258
- name = "Smaller equal"
259
- arg_name = "lte"
260
-
261
- def apply(self, statement, col, value):
262
- if isinstance(value, datetime.datetime):
263
- value = value.timestamp()
264
- elif isinstance(value, datetime.date):
265
- value = datetime.datetime.combine(value, datetime.datetime.min.time())
266
-
267
- return self._apply(
268
- statement, col, (col, gremlin_python.process.traversal.P.lte(value))
269
- )
270
-
271
-
272
- class GremlinFilterIn(GremlinBaseFilter):
273
- name = "One of"
274
- arg_name = "in"
275
-
276
- def apply(self, statement, col, value):
277
- return self._apply(
278
- statement, col, (col, gremlin_python.process.traversal.P.within(value))
279
- )
280
-
281
-
282
- class GremlinFilterBetween(GremlinBaseFilter):
283
- name = "Between"
284
- arg_name = "bw"
285
-
286
- def apply(self, statement, col, value):
287
- if not isinstance(value, (list, tuple)) or len(value) != 2:
288
- raise ValueError("Value must be a list or tuple with two elements.")
289
-
290
- if isinstance(value[0], datetime.datetime):
291
- value = [v.timestamp() for v in value]
292
- elif isinstance(value[0], datetime.date):
293
- value = [
294
- datetime.datetime.combine(v, datetime.datetime.min.time())
295
- for v in value
296
- ]
297
-
298
- return self._apply(
299
- statement,
300
- col,
301
- (col, gremlin_python.process.traversal.P.between(*value)),
302
- )
303
-
304
-
305
- class GremlinFilterRelationOneToOneOrManyToOneEqual(
306
- GremlinBaseFilterRelationOneToOneOrManyToOne, GremlinFilterEqual
307
- ):
308
- arg_name = "rel_o_m"
309
-
310
- def apply(self, statement, col, value):
311
- return statement.where(self._rel_apply(col, value))
312
-
313
-
314
- class GremlinFilterRelationOneToManyOrManyToManyIn(
315
- GremlinBaseFilterRelationOneToManyOrManyToMany, GremlinFilterEqual
316
- ):
317
- name = "In"
318
- arg_name = "rel_m_m"
319
-
320
- def apply(self, statement, col, value):
321
- for filter in self._rel_apply(col, value):
322
- statement = statement.where(filter)
323
- return statement
324
-
325
-
326
- class GremlinFilterConverter:
327
- """
328
- Helper class to get available filters for a gremlin column type.
329
- """
330
-
331
- conversion_table = (
332
- (
333
- "is_relation_one_to_one",
334
- [
335
- GremlinFilterRelationOneToOneOrManyToOneEqual,
336
- # GremlinFilterRelationOneToOneOrManyToOneNotEqual, # TODO: Not implemented yet
337
- # FilterTextContains,
338
- ],
339
- ),
340
- (
341
- "is_relation_many_to_one",
342
- [
343
- GremlinFilterRelationOneToOneOrManyToOneEqual,
344
- # GremlinFilterRelationOneToOneOrManyToOneNotEqual, # TODO: Not implemented yet
345
- # FilterTextContains,
346
- ],
347
- ),
348
- (
349
- "is_relation_one_to_many",
350
- [
351
- GremlinFilterRelationOneToManyOrManyToManyIn,
352
- # GremlinFilterRelationOneToManyOrManyToManyNotIn, # TODO: Not implemented yet
353
- # FilterTextContains,
354
- ],
355
- ),
356
- (
357
- "is_relation_many_to_many",
358
- [
359
- GremlinFilterRelationOneToManyOrManyToManyIn,
360
- # GremlinFilterRelationOneToManyOrManyToManyNotIn, # TODO: Not implemented yet
361
- # FilterTextContains,
362
- ],
363
- ),
364
- (
365
- "is_enum",
366
- [
367
- GremlinFilterTextContains,
368
- GremlinFilterEqual,
369
- GremlinFilterNotEqual,
370
- GremlinFilterIn,
371
- ],
372
- ),
373
- (
374
- "is_boolean",
375
- [GremlinFilterEqual, GremlinFilterNotEqual],
376
- ),
377
- (
378
- "is_text",
379
- [
380
- GremlinFilterTextContains,
381
- GremlinFilterStartsWith,
382
- GremlinFilterNotStartsWith,
383
- GremlinFilterEndsWith,
384
- GremlinFilterNotEndsWith,
385
- GremlinFilterContains,
386
- GremlinFilterNotContains,
387
- GremlinFilterEqual,
388
- GremlinFilterNotEqual,
389
- GremlinFilterIn,
390
- ],
391
- ),
392
- (
393
- "is_string",
394
- [
395
- GremlinFilterTextContains,
396
- GremlinFilterStartsWith,
397
- GremlinFilterNotStartsWith,
398
- GremlinFilterEndsWith,
399
- GremlinFilterNotEndsWith,
400
- GremlinFilterContains,
401
- GremlinFilterNotContains,
402
- GremlinFilterEqual,
403
- GremlinFilterNotEqual,
404
- GremlinFilterIn,
405
- ],
406
- ),
407
- (
408
- "is_json",
409
- [
410
- GremlinFilterTextContains,
411
- GremlinFilterStartsWith,
412
- GremlinFilterNotStartsWith,
413
- GremlinFilterEndsWith,
414
- GremlinFilterNotEndsWith,
415
- GremlinFilterContains,
416
- GremlinFilterNotContains,
417
- GremlinFilterEqual,
418
- GremlinFilterNotEqual,
419
- GremlinFilterIn,
420
- ],
421
- ),
422
- (
423
- "is_integer",
424
- [
425
- GremlinFilterBetween,
426
- GremlinFilterEqual,
427
- GremlinFilterNotEqual,
428
- GremlinFilterGreater,
429
- GremlinFilterSmaller,
430
- GremlinFilterGreaterEqual,
431
- GremlinFilterSmallerEqual,
432
- GremlinFilterIn,
433
- ],
434
- ),
435
- (
436
- "is_date",
437
- [
438
- GremlinFilterBetween,
439
- GremlinFilterEqual,
440
- GremlinFilterNotEqual,
441
- GremlinFilterGreater,
442
- GremlinFilterSmaller,
443
- GremlinFilterGreaterEqual,
444
- GremlinFilterSmallerEqual,
445
- GremlinFilterIn,
446
- ],
447
- ),
448
- (
449
- "is_datetime",
450
- [
451
- GremlinFilterBetween,
452
- GremlinFilterEqual,
453
- GremlinFilterNotEqual,
454
- GremlinFilterGreater,
455
- GremlinFilterSmaller,
456
- GremlinFilterGreaterEqual,
457
- GremlinFilterSmallerEqual,
458
- GremlinFilterIn,
459
- ],
460
- ),
461
- )