fastapi-factory-utilities 0.4.0__tar.gz → 0.8.2__tar.gz
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.
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/PKG-INFO +14 -8
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/pyproject.toml +29 -15
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/api/__init__.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/api/v1/sys/health.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/application.py +22 -26
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/builder.py +8 -32
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/fastapi_builder.py +3 -2
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/exceptions.py +87 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/__init__.py +7 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/abstracts.py +40 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/__init__.py +25 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/abstract.py +48 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/configs.py +85 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/depends.py +20 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/exceptions.py +29 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/exchange.py +69 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/listener/__init__.py +7 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/listener/abstract.py +72 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/message.py +86 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/plugins.py +84 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/publisher/__init__.py +7 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/publisher/abstract.py +66 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/queue.py +88 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py +26 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/builder.py +3 -3
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/configs.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/documents.py +1 -1
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/odm_plugin/helpers.py +16 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/odm_plugin/plugins.py +155 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py +1 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py +17 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/instruments/__init__.py +85 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/plugins.py +137 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/__init__.py +31 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/configs.py +12 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/depends.py +51 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/exceptions.py +13 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/plugin.py +41 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/taskiq_plugins/schedulers.py +187 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/protocols.py +32 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/__init__.py +5 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/abstracts.py +42 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/__init__.py +41 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/configs.py +32 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/decoders.py +130 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/exceptions.py +23 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/objects.py +107 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/services.py +176 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/stores.py +43 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/types.py +9 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/jwt/verifiers.py +46 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/security/kratos.py +98 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/services/hydra/__init__.py +20 -0
- fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/services/hydra/services.py +200 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/exceptions.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/status.py +2 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/yaml_reader.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/app.py +15 -5
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/entities/books/__init__.py +1 -1
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/models/books/__init__.py +1 -1
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/app/plugin_manager/__init__.py +0 -15
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/app/plugin_manager/exceptions.py +0 -33
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/app/plugin_manager/plugin_manager.py +0 -190
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/exceptions.py +0 -52
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/plugins/__init__.py +0 -36
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/plugins/example/__init__.py +0 -31
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/plugins/httpx_plugin/__init__.py +0 -31
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py +0 -169
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py +0 -130
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/protocols.py +0 -85
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/security/jwt.py +0 -158
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/security/kratos.py +0 -98
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/services/hydra/__init__.py +0 -13
- fastapi_factory_utilities-0.4.0/src/fastapi_factory_utilities/core/services/hydra/services.py +0 -122
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/LICENSE +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/README.md +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/__main__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/api/tags.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/api/v1/sys/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/api/v1/sys/readiness.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/__init__.py +4 -4
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/config.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/enums.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/app/exceptions.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/depends.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/odm_plugin/exceptions.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/exceptions.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/plugins/opentelemetry_plugin/helpers.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/hydra/exceptions.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/hydra/objects.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/kratos/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/kratos/enums.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/kratos/exceptions.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/kratos/objects.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/kratos/services.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/__init__.py +2 -2
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/enums.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/health_calculator_strategies.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/readiness_calculator_strategies.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/services.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/services/status/types.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/configs.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/importlib.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/log.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/core/utils/uvicorn.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/__main__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/api/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/api/books/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/api/books/responses.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/api/books/routes.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/application.yaml +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/entities/books/entities.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/entities/books/enums.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/entities/books/types.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/models/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/models/books/document.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/models/books/repository.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/services/books/__init__.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/example/services/books/services.py +0 -0
- {fastapi_factory_utilities-0.4.0 → fastapi_factory_utilities-0.8.2}/src/fastapi_factory_utilities/py.typed +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_factory_utilities
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie,
|
|
3
|
+
Version: 0.8.2
|
|
4
|
+
Summary: Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie, Taskiq, AioPika and OpenTelemetry.
|
|
5
5
|
License: MIT
|
|
6
|
-
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: python,fastapi,beanie,taskiq,opentelemetry,microservices
|
|
7
8
|
Author: miragecentury
|
|
8
9
|
Author-email: victorien.vanroye@gmail.com
|
|
9
10
|
Maintainer: miragecentury
|
|
@@ -18,12 +19,14 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
18
19
|
Classifier: Topic :: Software Development :: Libraries
|
|
19
20
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Dist: aio-pika (>=9.5.7,<10.0.0)
|
|
21
23
|
Requires-Dist: aiohttp[speedups] (>=3.12.13,<4.0.0)
|
|
22
24
|
Requires-Dist: beanie (>=1.30.0,<2.0.0)
|
|
23
25
|
Requires-Dist: fastapi (>=0.115.13,<1)
|
|
24
26
|
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc (>=1.26.0,<2.0.0)
|
|
25
27
|
Requires-Dist: opentelemetry-exporter-otlp-proto-http (>=1.26.0,<2.0.0)
|
|
26
|
-
Requires-Dist: opentelemetry-instrumentation-
|
|
28
|
+
Requires-Dist: opentelemetry-instrumentation-aio-pika (>=0.59b0,<0.60)
|
|
29
|
+
Requires-Dist: opentelemetry-instrumentation-aiohttp-client (>=0,<1)
|
|
27
30
|
Requires-Dist: opentelemetry-instrumentation-fastapi (>=0,<1)
|
|
28
31
|
Requires-Dist: opentelemetry-instrumentation-pymongo (>=0,<1)
|
|
29
32
|
Requires-Dist: opentelemetry-propagator-b3 (>=1.26.0,<2.0.0)
|
|
@@ -31,13 +34,16 @@ Requires-Dist: opentelemetry-sdk (>=1.26.0,<2.0.0)
|
|
|
31
34
|
Requires-Dist: pyaml (>=25.1.0,<26.0.0)
|
|
32
35
|
Requires-Dist: pydantic (>=2.8.2,<3.0.0)
|
|
33
36
|
Requires-Dist: pyjwt (>=2.10.1,<3.0.0)
|
|
34
|
-
Requires-Dist: pymongo (>=4.9.2,<4.
|
|
37
|
+
Requires-Dist: pymongo (>=4.9.2,<4.16.0)
|
|
35
38
|
Requires-Dist: reactivex (>=4.0.4,<5.0.0)
|
|
36
39
|
Requires-Dist: structlog (>=24.1,<26.0)
|
|
40
|
+
Requires-Dist: taskiq-dependencies (>=1.5.8,<2.0.0)
|
|
41
|
+
Requires-Dist: taskiq-fastapi (>=0.3.5,<0.4.0)
|
|
42
|
+
Requires-Dist: taskiq-redis (>=1.0.9,<2.0.0)
|
|
37
43
|
Requires-Dist: typer (>=0,<1)
|
|
38
44
|
Requires-Dist: uvicorn (>=0.34.3,<1)
|
|
39
|
-
Project-URL: Homepage, https://github.com/
|
|
40
|
-
Project-URL: Repository, https://github.com/
|
|
45
|
+
Project-URL: Homepage, https://github.com/DeerHide/fastapi_factory_utilities
|
|
46
|
+
Project-URL: Repository, https://github.com/DeerHide/fastapi_factory_utilities
|
|
41
47
|
Description-Content-Type: text/markdown
|
|
42
48
|
|
|
43
49
|
# fastapi_factory_utilities
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "fastapi_factory_utilities"
|
|
3
|
-
homepage = "https://github.com/
|
|
4
|
-
repository = "https://github.com/
|
|
5
|
-
keywords = ["python", "fastapi", "beanie", "
|
|
6
|
-
version = "0.
|
|
7
|
-
description = "Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie,
|
|
3
|
+
homepage = "https://github.com/DeerHide/fastapi_factory_utilities"
|
|
4
|
+
repository = "https://github.com/DeerHide/fastapi_factory_utilities"
|
|
5
|
+
keywords = ["python", "fastapi", "beanie", "taskiq", "opentelemetry", "microservices"]
|
|
6
|
+
version = "0.8.2"
|
|
7
|
+
description = "Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie, Taskiq, AioPika and OpenTelemetry."
|
|
8
8
|
authors = ["miragecentury <victorien.vanroye@gmail.com>"]
|
|
9
9
|
maintainers = ["miragecentury <victorien.vanroye@gmail.com>"]
|
|
10
10
|
license = "MIT"
|
|
@@ -24,6 +24,11 @@ classifiers = [
|
|
|
24
24
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
25
25
|
]
|
|
26
26
|
|
|
27
|
+
[[tool.poetry.source]]
|
|
28
|
+
name = "velmios"
|
|
29
|
+
url = "https://pypi.velmios.io/simple"
|
|
30
|
+
priority = "explicit"
|
|
31
|
+
|
|
27
32
|
[tool.poetry.dependencies]
|
|
28
33
|
python = "~3.12"
|
|
29
34
|
structlog = ">=24.1,<26.0"
|
|
@@ -38,12 +43,17 @@ opentelemetry-instrumentation-fastapi = "^0"
|
|
|
38
43
|
opentelemetry-propagator-b3 = "^1.26.0"
|
|
39
44
|
beanie = "^1.30.0"
|
|
40
45
|
opentelemetry-instrumentation-pymongo = "^0"
|
|
41
|
-
pymongo = "
|
|
46
|
+
pymongo = ">=4.9.2,<4.16.0"
|
|
42
47
|
pyaml = "^25.1.0"
|
|
43
48
|
reactivex = "^4.0.4"
|
|
44
49
|
pyjwt = "^2.10.1"
|
|
45
50
|
aiohttp = { version="^3.12.13", extras=["speedups"] }
|
|
46
|
-
opentelemetry-instrumentation-aiohttp-client = "^0
|
|
51
|
+
opentelemetry-instrumentation-aiohttp-client = "^0"
|
|
52
|
+
aio-pika = "^9.5.7"
|
|
53
|
+
opentelemetry-instrumentation-aio-pika = "^0.59b0"
|
|
54
|
+
taskiq-dependencies = { version="^1.5.8", source="velmios"}
|
|
55
|
+
taskiq-fastapi = "^0.3.5"
|
|
56
|
+
taskiq-redis = "^1.0.9"
|
|
47
57
|
|
|
48
58
|
[tool.poetry.group.test]
|
|
49
59
|
optional = true
|
|
@@ -52,23 +62,23 @@ optional = true
|
|
|
52
62
|
mypy = "^1.10.0"
|
|
53
63
|
types-requests = "^2.32.0.20240712"
|
|
54
64
|
types-pyyaml = "^6.0.12.20240311"
|
|
55
|
-
pylint = {version="
|
|
56
|
-
black = "^
|
|
65
|
+
pylint = {version=">=3.2.2,<5.0.0", extras=["spelling"]}
|
|
66
|
+
black = "^25.9.0"
|
|
57
67
|
pre-commit = "^4.0.1"
|
|
58
68
|
pyupgrade = "^3.15.2"
|
|
59
69
|
pytest = "^8.2.0"
|
|
60
70
|
pytest-xdist = "^3.6.1"
|
|
61
|
-
pytest-cov = "^
|
|
62
|
-
ruff = "^0.
|
|
63
|
-
pytest-asyncio = "
|
|
71
|
+
pytest-cov = "^7.0.0"
|
|
72
|
+
ruff = "^0.14"
|
|
73
|
+
pytest-asyncio = ">=0.25,<1.3"
|
|
64
74
|
pytest-mongo = "^3.1.0"
|
|
65
75
|
locust = "^2.32.4"
|
|
66
|
-
testcontainers = { version="^4.9.0", extras=["mongodb"] }
|
|
76
|
+
testcontainers = { version="^4.9.0", extras=["mongodb","rabbitmq", "redis"] }
|
|
67
77
|
types-deprecated = "^1.2.15.20241117"
|
|
68
78
|
types-pygments = "^2.18.0.20240506"
|
|
69
79
|
types-colorama = "^0.4.15.20240311"
|
|
70
|
-
types-protobuf = "
|
|
71
|
-
types-psutil = "
|
|
80
|
+
types-protobuf = ">=5.29.1.20241207,<7.0.0.0"
|
|
81
|
+
types-psutil = ">=6.1.0.20241221,<8.0.0.0"
|
|
72
82
|
types-pyopenssl = "^24.1.0.20240722"
|
|
73
83
|
types-ujson = "^5.10.0.20240515"
|
|
74
84
|
httpx = "^0.28.1"
|
|
@@ -88,6 +98,9 @@ addopts = "--import-mode=importlib -n auto --color=yes"
|
|
|
88
98
|
filterwarnings = [
|
|
89
99
|
"ignore:.*datetime.datetime.utcfromtimestamp().*:DeprecationWarning", # reactivex
|
|
90
100
|
"ignore:.*datetime.datetime.utcnow().*:DeprecationWarning", # reactivex
|
|
101
|
+
"ignore::pydantic.warnings.PydanticDeprecatedSince211",
|
|
102
|
+
"ignore:The @wait_container_is_ready decorator is deprecated.*:DeprecationWarning", # testcontainers
|
|
103
|
+
"ignore:The wait_for_logs function with string or callable predicates is deprecated.*:DeprecationWarning", # testcontainers
|
|
91
104
|
]
|
|
92
105
|
asyncio_mode = "auto"
|
|
93
106
|
asyncio_default_fixture_loop_scope = "function"
|
|
@@ -108,6 +121,7 @@ mypy_path = "src:tests"
|
|
|
108
121
|
namespace_packages = true
|
|
109
122
|
plugins = ["pydantic.mypy"]
|
|
110
123
|
follow_imports = "silent"
|
|
124
|
+
follow_untyped_imports = true
|
|
111
125
|
warn_redundant_casts = true
|
|
112
126
|
warn_unused_ignores = true
|
|
113
127
|
disallow_any_generics = true
|
|
@@ -10,10 +10,10 @@ from pydantic import BaseModel
|
|
|
10
10
|
|
|
11
11
|
from fastapi_factory_utilities.core.services.status.enums import HealthStatusEnum
|
|
12
12
|
from fastapi_factory_utilities.core.services.status.services import (
|
|
13
|
-
ComponentInstanceKey,
|
|
14
13
|
StatusService,
|
|
15
14
|
depends_status_service,
|
|
16
15
|
)
|
|
16
|
+
from fastapi_factory_utilities.core.services.status.types import ComponentInstanceKey
|
|
17
17
|
|
|
18
18
|
api_v1_sys_health = APIRouter(prefix="/health")
|
|
19
19
|
|
|
@@ -12,10 +12,7 @@ from structlog.stdlib import BoundLogger, get_logger
|
|
|
12
12
|
from fastapi_factory_utilities.core.api import api
|
|
13
13
|
from fastapi_factory_utilities.core.app.config import RootConfig
|
|
14
14
|
from fastapi_factory_utilities.core.app.fastapi_builder import FastAPIBuilder
|
|
15
|
-
from fastapi_factory_utilities.core.
|
|
16
|
-
PluginManager,
|
|
17
|
-
)
|
|
18
|
-
from fastapi_factory_utilities.core.plugins import PluginsEnum
|
|
15
|
+
from fastapi_factory_utilities.core.plugins import PluginAbstract
|
|
19
16
|
from fastapi_factory_utilities.core.services.status.services import StatusService
|
|
20
17
|
|
|
21
18
|
_logger: BoundLogger = get_logger(__name__)
|
|
@@ -31,12 +28,10 @@ class ApplicationAbstract(ABC):
|
|
|
31
28
|
# TODO: Find a way to remove this from here
|
|
32
29
|
ODM_DOCUMENT_MODELS: ClassVar[list[type[Document]]]
|
|
33
30
|
|
|
34
|
-
DEFAULT_PLUGINS_ACTIVATED: ClassVar[list[PluginsEnum]] = []
|
|
35
|
-
|
|
36
31
|
def __init__(
|
|
37
32
|
self,
|
|
38
33
|
root_config: RootConfig,
|
|
39
|
-
|
|
34
|
+
plugins: list[PluginAbstract],
|
|
40
35
|
fastapi_builder: FastAPIBuilder,
|
|
41
36
|
) -> None:
|
|
42
37
|
"""Instantiate the application."""
|
|
@@ -44,9 +39,25 @@ class ApplicationAbstract(ABC):
|
|
|
44
39
|
self.fastapi_builder: FastAPIBuilder = fastapi_builder
|
|
45
40
|
# Add the API router to the FastAPI application
|
|
46
41
|
self.fastapi_builder.add_api_router(router=api, without_resource_path=True)
|
|
47
|
-
self.
|
|
42
|
+
self.plugins: list[PluginAbstract] = plugins
|
|
48
43
|
self._add_to_state: dict[str, Any] = {}
|
|
49
44
|
|
|
45
|
+
def load_plugins(self) -> None:
|
|
46
|
+
"""Load the plugins."""
|
|
47
|
+
for plugin in self.plugins:
|
|
48
|
+
plugin.set_application(application=self)
|
|
49
|
+
plugin.on_load()
|
|
50
|
+
|
|
51
|
+
async def startup_plugins(self) -> None:
|
|
52
|
+
"""Startup the plugins."""
|
|
53
|
+
for plugin in self.plugins:
|
|
54
|
+
await plugin.on_startup()
|
|
55
|
+
|
|
56
|
+
async def shutdown_plugins(self) -> None:
|
|
57
|
+
"""Shutdown the plugins."""
|
|
58
|
+
for plugin in self.plugins:
|
|
59
|
+
await plugin.on_shutdown()
|
|
60
|
+
|
|
50
61
|
def setup(self) -> None:
|
|
51
62
|
"""Initialize the application."""
|
|
52
63
|
# Initialize FastAPI application
|
|
@@ -61,10 +72,7 @@ class ApplicationAbstract(ABC):
|
|
|
61
72
|
self.configure()
|
|
62
73
|
self._apply_states_to_fastapi_app()
|
|
63
74
|
# Initialize PluginManager
|
|
64
|
-
self.
|
|
65
|
-
self.plugin_manager.load()
|
|
66
|
-
# Add the states to the FastAPI app
|
|
67
|
-
self._import_states_from_plugin_manager()
|
|
75
|
+
self.load_plugins()
|
|
68
76
|
|
|
69
77
|
def _apply_states_to_fastapi_app(self) -> None:
|
|
70
78
|
# Add manually added states to the FastAPI app
|
|
@@ -74,13 +82,6 @@ class ApplicationAbstract(ABC):
|
|
|
74
82
|
setattr(self._asgi_app.state, key, value)
|
|
75
83
|
self._add_to_state.clear()
|
|
76
84
|
|
|
77
|
-
def _import_states_from_plugin_manager(self) -> None:
|
|
78
|
-
"""Import the states from the plugins."""
|
|
79
|
-
for state in self.plugin_manager.states:
|
|
80
|
-
self.add_to_state(key=state.key, value=state.value)
|
|
81
|
-
self.plugin_manager.clear_states()
|
|
82
|
-
self._apply_states_to_fastapi_app()
|
|
83
|
-
|
|
84
85
|
def add_to_state(self, key: str, value: Any) -> None:
|
|
85
86
|
"""Add a value to the FastAPI app state."""
|
|
86
87
|
if key in self._add_to_state:
|
|
@@ -105,14 +106,13 @@ class ApplicationAbstract(ABC):
|
|
|
105
106
|
@asynccontextmanager
|
|
106
107
|
async def fastapi_lifespan(self, fastapi: FastAPI) -> AsyncGenerator[None, None]: # pylint: disable=unused-argument
|
|
107
108
|
"""FastAPI lifespan context manager."""
|
|
108
|
-
await self.
|
|
109
|
-
self._import_states_from_plugin_manager()
|
|
109
|
+
await self.startup_plugins()
|
|
110
110
|
await self.on_startup()
|
|
111
111
|
try:
|
|
112
112
|
yield
|
|
113
113
|
finally:
|
|
114
114
|
await self.on_shutdown()
|
|
115
|
-
await self.
|
|
115
|
+
await self.shutdown_plugins()
|
|
116
116
|
|
|
117
117
|
def get_config(self) -> RootConfig:
|
|
118
118
|
"""Get the configuration."""
|
|
@@ -122,10 +122,6 @@ class ApplicationAbstract(ABC):
|
|
|
122
122
|
"""Get the ASGI application."""
|
|
123
123
|
return self._asgi_app
|
|
124
124
|
|
|
125
|
-
def get_plugin_manager(self) -> PluginManager:
|
|
126
|
-
"""Get the plugin manager."""
|
|
127
|
-
return self.plugin_manager
|
|
128
|
-
|
|
129
125
|
def get_status_service(self) -> StatusService:
|
|
130
126
|
"""Get the status service."""
|
|
131
127
|
return self.status_service
|
|
@@ -4,10 +4,7 @@ from typing import Any, Generic, Self, TypeVar, get_args
|
|
|
4
4
|
|
|
5
5
|
from fastapi_factory_utilities.core.app.config import GenericConfigBuilder, RootConfig
|
|
6
6
|
from fastapi_factory_utilities.core.app.fastapi_builder import FastAPIBuilder
|
|
7
|
-
from fastapi_factory_utilities.core.
|
|
8
|
-
PluginManager,
|
|
9
|
-
)
|
|
10
|
-
from fastapi_factory_utilities.core.plugins import PluginsEnum
|
|
7
|
+
from fastapi_factory_utilities.core.plugins import PluginAbstract
|
|
11
8
|
from fastapi_factory_utilities.core.utils.log import LogModeEnum, setup_log
|
|
12
9
|
from fastapi_factory_utilities.core.utils.uvicorn import UvicornUtils
|
|
13
10
|
|
|
@@ -19,21 +16,16 @@ T = TypeVar("T", bound=ApplicationAbstract)
|
|
|
19
16
|
class ApplicationGenericBuilder(Generic[T]):
|
|
20
17
|
"""Application generic builder."""
|
|
21
18
|
|
|
22
|
-
def __init__(self,
|
|
19
|
+
def __init__(self, plugins: list[PluginAbstract] | None = None) -> None:
|
|
23
20
|
"""Instanciate the ApplicationGenericBuilder."""
|
|
24
21
|
self._uvicorn_utils: UvicornUtils | None = None
|
|
25
22
|
self._root_config: RootConfig | None = None
|
|
26
|
-
self.
|
|
23
|
+
self._plugins: list[PluginAbstract] = plugins or []
|
|
27
24
|
self._fastapi_builder: FastAPIBuilder | None = None
|
|
28
25
|
generic_args: tuple[Any, ...] = get_args(self.__orig_bases__[0]) # type: ignore
|
|
29
26
|
self._application_class: type[T] = generic_args[0]
|
|
30
|
-
self._plugins_activation_list: list[PluginsEnum]
|
|
31
|
-
if plugins_activation_list is None:
|
|
32
|
-
self._plugins_activation_list = self._application_class.DEFAULT_PLUGINS_ACTIVATED
|
|
33
|
-
else:
|
|
34
|
-
self._plugins_activation_list = plugins_activation_list
|
|
35
27
|
|
|
36
|
-
def add_plugin_to_activate(self, plugin:
|
|
28
|
+
def add_plugin_to_activate(self, plugin: PluginAbstract) -> Self:
|
|
37
29
|
"""Add a plugin to activate.
|
|
38
30
|
|
|
39
31
|
Args:
|
|
@@ -42,7 +34,7 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
42
34
|
Returns:
|
|
43
35
|
Self: The builder.
|
|
44
36
|
"""
|
|
45
|
-
self.
|
|
37
|
+
self._plugins.append(plugin)
|
|
46
38
|
return self
|
|
47
39
|
|
|
48
40
|
def add_config(self, config: RootConfig) -> Self:
|
|
@@ -57,18 +49,6 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
57
49
|
self._root_config = config
|
|
58
50
|
return self
|
|
59
51
|
|
|
60
|
-
def add_plugin_manager(self, plugin_manager: PluginManager) -> Self:
|
|
61
|
-
"""Add the plugin manager to the builder.
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
plugin_manager (PluginManager): The plugin manager.
|
|
65
|
-
|
|
66
|
-
Returns:
|
|
67
|
-
Self: The builder.
|
|
68
|
-
"""
|
|
69
|
-
self._plugin_manager = plugin_manager
|
|
70
|
-
return self
|
|
71
|
-
|
|
72
52
|
def add_fastapi_builder(self, fastapi_builder: FastAPIBuilder) -> Self:
|
|
73
53
|
"""Add the FastAPI builder to the builder.
|
|
74
54
|
|
|
@@ -83,7 +63,7 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
83
63
|
|
|
84
64
|
def _build_from_package_root_config(self) -> RootConfig:
|
|
85
65
|
"""Build the configuration from the package."""
|
|
86
|
-
return GenericConfigBuilder[self._application_class.CONFIG_CLASS](
|
|
66
|
+
return GenericConfigBuilder[self._application_class.CONFIG_CLASS]( # type: ignore
|
|
87
67
|
package_name=self._application_class.PACKAGE_NAME,
|
|
88
68
|
config_class=self._application_class.CONFIG_CLASS,
|
|
89
69
|
).build()
|
|
@@ -97,11 +77,6 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
97
77
|
Returns:
|
|
98
78
|
T: The application.
|
|
99
79
|
"""
|
|
100
|
-
# Plugin manager
|
|
101
|
-
if self._plugin_manager is None:
|
|
102
|
-
self._plugin_manager = PluginManager()
|
|
103
|
-
for plugin in self._plugins_activation_list:
|
|
104
|
-
self._plugin_manager.activate(plugin=plugin)
|
|
105
80
|
# RootConfig
|
|
106
81
|
self._root_config = self._root_config or self._build_from_package_root_config()
|
|
107
82
|
# FastAPIBuilder
|
|
@@ -109,7 +84,7 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
109
84
|
|
|
110
85
|
application: T = self._application_class(
|
|
111
86
|
root_config=self._root_config,
|
|
112
|
-
|
|
87
|
+
plugins=self._plugins,
|
|
113
88
|
fastapi_builder=self._fastapi_builder,
|
|
114
89
|
**kwargs,
|
|
115
90
|
)
|
|
@@ -125,6 +100,7 @@ class ApplicationGenericBuilder(Generic[T]):
|
|
|
125
100
|
"""Build the application and serve it with Uvicorn."""
|
|
126
101
|
uvicorn_utils: UvicornUtils = self._uvicorn_utils or self.build_as_uvicorn_utils()
|
|
127
102
|
|
|
103
|
+
assert self._root_config is not None
|
|
128
104
|
setup_log(mode=LogModeEnum.CONSOLE, logging_config=self._root_config.logging)
|
|
129
105
|
|
|
130
106
|
try:
|
|
@@ -64,7 +64,7 @@ class FastAPIBuilder:
|
|
|
64
64
|
title=self._root_config.application.service_name,
|
|
65
65
|
description="",
|
|
66
66
|
version=self._root_config.application.version,
|
|
67
|
-
lifespan=lifespan,
|
|
67
|
+
lifespan=lifespan,
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
fastapi.add_middleware(
|
|
@@ -77,7 +77,8 @@ class FastAPIBuilder:
|
|
|
77
77
|
|
|
78
78
|
for middleware_args in self._middleware_list:
|
|
79
79
|
fastapi.add_middleware(
|
|
80
|
-
middleware_class=middleware_args.middleware_class,
|
|
80
|
+
middleware_class=middleware_args.middleware_class, # type: ignore
|
|
81
|
+
**middleware_args.kwargs, # pyright: ignore
|
|
81
82
|
)
|
|
82
83
|
|
|
83
84
|
fastapi.include_router(router=self._base_router)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""FastAPI Factory Utilities exceptions."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Any, cast
|
|
5
|
+
|
|
6
|
+
from opentelemetry.trace import Span, get_current_span
|
|
7
|
+
from opentelemetry.util.types import AttributeValue
|
|
8
|
+
from structlog.stdlib import BoundLogger, get_logger
|
|
9
|
+
|
|
10
|
+
_logger: BoundLogger = get_logger()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FastAPIFactoryUtilitiesError(Exception):
|
|
14
|
+
"""Base exception for the FastAPI Factory Utilities."""
|
|
15
|
+
|
|
16
|
+
FILTERED_ATTRIBUTES: tuple[str, ...] = ()
|
|
17
|
+
DEFAULT_LOGGING_LEVEL: int = logging.ERROR
|
|
18
|
+
DEFAULT_MESSAGE: str | None = None
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
*args: object,
|
|
23
|
+
**kwargs: Any,
|
|
24
|
+
) -> None:
|
|
25
|
+
"""Instantiate the exception.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
*args: The arguments.
|
|
29
|
+
**kwargs: The keyword arguments.
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
# If Default Message is not set, try to extract it from docstring (first line)
|
|
33
|
+
default_message: str = self.DEFAULT_MESSAGE or "An error occurred"
|
|
34
|
+
if self.DEFAULT_MESSAGE is None and self.__doc__ is not None:
|
|
35
|
+
default_message = self.__doc__.split("\n", maxsplit=1)[0]
|
|
36
|
+
# Extract the message and the level from the kwargs if they are present
|
|
37
|
+
self.message: str | None = cast(str | None, kwargs.pop("message", None))
|
|
38
|
+
self.level: int = cast(int, kwargs.pop("level", self.DEFAULT_LOGGING_LEVEL))
|
|
39
|
+
|
|
40
|
+
# If the message is not present, try to extract it from the args
|
|
41
|
+
if self.message is None and len(args) > 0 and isinstance(args[0], str):
|
|
42
|
+
self.message = args[0]
|
|
43
|
+
elif self.message is None:
|
|
44
|
+
self.message = default_message
|
|
45
|
+
|
|
46
|
+
# Log the Exception
|
|
47
|
+
if self.message:
|
|
48
|
+
_logger.log(level=self.level, event=self.message)
|
|
49
|
+
|
|
50
|
+
# Set the kwargs as attributes of the exception
|
|
51
|
+
for key, value in kwargs.items():
|
|
52
|
+
if key in self.FILTERED_ATTRIBUTES:
|
|
53
|
+
continue
|
|
54
|
+
setattr(self, key, value)
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
# Propagate the exception
|
|
58
|
+
span: Span = get_current_span()
|
|
59
|
+
# If not otel is setup, INVALID_SPAN is retrieved from get_current_span
|
|
60
|
+
# and it will respond False to the is_recording method
|
|
61
|
+
if span.is_recording():
|
|
62
|
+
span.record_exception(self)
|
|
63
|
+
for key, value in kwargs.items():
|
|
64
|
+
if key in self.FILTERED_ATTRIBUTES:
|
|
65
|
+
continue
|
|
66
|
+
attribute_value: AttributeValue
|
|
67
|
+
if not isinstance(value, (str, bool, int, float)):
|
|
68
|
+
attribute_value = str(value)
|
|
69
|
+
else:
|
|
70
|
+
attribute_value = value
|
|
71
|
+
span.set_attribute(key, attribute_value)
|
|
72
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
73
|
+
# Suppress any errors that occur while propagating the exception
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
# Call the parent class
|
|
77
|
+
super().__init__(*args)
|
|
78
|
+
|
|
79
|
+
def __str__(self) -> str:
|
|
80
|
+
"""Return the string representation of the exception.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
str: The message if available, otherwise the default exception string.
|
|
84
|
+
"""
|
|
85
|
+
if self.message is not None:
|
|
86
|
+
return self.message
|
|
87
|
+
return super().__str__()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Abstracts for the plugins."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Self
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from fastapi_factory_utilities.core.protocols import ApplicationAbstractProtocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PluginAbstract(ABC):
|
|
11
|
+
"""Abstract class for the plugins."""
|
|
12
|
+
|
|
13
|
+
def __init__(self) -> None:
|
|
14
|
+
"""Initialize the plugin."""
|
|
15
|
+
self._application: ApplicationAbstractProtocol | None = None
|
|
16
|
+
|
|
17
|
+
def set_application(self, application: "ApplicationAbstractProtocol") -> Self:
|
|
18
|
+
"""Set the application."""
|
|
19
|
+
self._application = application
|
|
20
|
+
return self
|
|
21
|
+
|
|
22
|
+
def _add_to_state(self, key: str, value: Any) -> None:
|
|
23
|
+
"""Add to the state."""
|
|
24
|
+
assert self._application is not None
|
|
25
|
+
setattr(self._application.get_asgi_app().state, key, value)
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def on_load(self) -> None:
|
|
29
|
+
"""On load."""
|
|
30
|
+
raise NotImplementedError
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
async def on_startup(self) -> None:
|
|
34
|
+
"""On startup."""
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
async def on_shutdown(self) -> None:
|
|
39
|
+
"""On shutdown."""
|
|
40
|
+
raise NotImplementedError
|
fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Aiopika Plugin Module."""
|
|
2
|
+
|
|
3
|
+
from .configs import AiopikaConfig
|
|
4
|
+
from .depends import depends_aiopika_robust_connection
|
|
5
|
+
from .exceptions import AiopikaPluginBaseError, AiopikaPluginConfigError
|
|
6
|
+
from .exchange import Exchange
|
|
7
|
+
from .listener import AbstractListener
|
|
8
|
+
from .message import AbstractMessage, SenderModel
|
|
9
|
+
from .plugins import AiopikaPlugin
|
|
10
|
+
from .publisher import AbstractPublisher
|
|
11
|
+
from .queue import Queue
|
|
12
|
+
|
|
13
|
+
__all__: list[str] = [
|
|
14
|
+
"AbstractListener",
|
|
15
|
+
"AbstractMessage",
|
|
16
|
+
"AbstractPublisher",
|
|
17
|
+
"AiopikaConfig",
|
|
18
|
+
"AiopikaPlugin",
|
|
19
|
+
"AiopikaPluginBaseError",
|
|
20
|
+
"AiopikaPluginConfigError",
|
|
21
|
+
"Exchange",
|
|
22
|
+
"Queue",
|
|
23
|
+
"SenderModel",
|
|
24
|
+
"depends_aiopika_robust_connection",
|
|
25
|
+
]
|
fastapi_factory_utilities-0.8.2/src/fastapi_factory_utilities/core/plugins/aiopika/abstract.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Provides the abstract class for the Aiopika plugin."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC
|
|
4
|
+
from typing import Self
|
|
5
|
+
|
|
6
|
+
from aio_pika.abc import AbstractChannel, AbstractRobustConnection
|
|
7
|
+
|
|
8
|
+
from .exceptions import AiopikaPluginBaseError, AiopikaPluginConnectionNotProvidedError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AbstractAiopikaResource(ABC):
|
|
12
|
+
"""Abstract class for the Aiopika resource."""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
"""Initialize the Aiopika resource."""
|
|
16
|
+
self._robust_connection: AbstractRobustConnection | None = None
|
|
17
|
+
self._channel: AbstractChannel | None = None
|
|
18
|
+
|
|
19
|
+
def set_robust_connection(self, robust_connection: AbstractRobustConnection) -> Self:
|
|
20
|
+
"""Set the robust connection."""
|
|
21
|
+
self._robust_connection = robust_connection
|
|
22
|
+
return self
|
|
23
|
+
|
|
24
|
+
def set_channel(self, channel: AbstractChannel) -> Self:
|
|
25
|
+
"""Set the channel."""
|
|
26
|
+
self._channel = channel
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
async def _acquire_channel(self) -> AbstractChannel:
|
|
30
|
+
"""Acquire the channel."""
|
|
31
|
+
if self._robust_connection is None:
|
|
32
|
+
raise AiopikaPluginConnectionNotProvidedError(
|
|
33
|
+
message="Robust connection not provided.",
|
|
34
|
+
)
|
|
35
|
+
if self._channel is None:
|
|
36
|
+
try:
|
|
37
|
+
self._channel = await self._robust_connection.channel()
|
|
38
|
+
except Exception as exception:
|
|
39
|
+
raise AiopikaPluginBaseError(
|
|
40
|
+
message="Failed to acquire the channel.",
|
|
41
|
+
) from exception
|
|
42
|
+
return self._channel
|
|
43
|
+
|
|
44
|
+
async def setup(self) -> Self:
|
|
45
|
+
"""Setup the Aiopika resource."""
|
|
46
|
+
if self._channel is None:
|
|
47
|
+
await self._acquire_channel()
|
|
48
|
+
return self
|