fast-clean 1.4.0__py3-none-any.whl → 1.4.1__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.
fast_clean/depends.py CHANGED
@@ -16,7 +16,6 @@ from stringcase import snakecase
16
16
 
17
17
  from .broker import BrokerFactory
18
18
  from .db import SessionFactory, SessionManagerImpl, SessionManagerProtocol
19
- from .redis import RedisManager
20
19
  from .repositories import (
21
20
  CacheManager,
22
21
  CacheRepositoryProtocol,
@@ -121,15 +120,8 @@ class CoreProvider(Provider):
121
120
  """
122
121
  Получаем репозиторий кеша.
123
122
  """
124
- settings = await settings_repository.get(CoreSettingsSchema)
125
- if settings.redis_dsn is not None:
126
- RedisManager.init(settings.redis_dsn)
127
123
  cache_settings = await settings_repository.get(CoreCacheSettingsSchema)
128
- if CacheManager.cache_repository is None:
129
- CacheManager.init(cache_settings, RedisManager.redis)
130
- if CacheManager.cache_repository is not None:
131
- return CacheManager.cache_repository
132
- raise ValueError('Cache is not initialized')
124
+ return CacheManager.init(cache_settings)
133
125
 
134
126
  @provide(scope=Scope.REQUEST)
135
127
  @staticmethod
@@ -201,14 +193,12 @@ class CoreProvider(Provider):
201
193
 
202
194
  @provide
203
195
  @staticmethod
204
- def get_lock_service(settings: CoreSettingsSchema) -> LockServiceProtocol:
196
+ def get_lock_service(cache_settings: CoreCacheSettingsSchema) -> LockServiceProtocol:
205
197
  """
206
198
  Получаем сервис распределенной блокировки.
207
199
  """
208
- assert settings.redis_dsn is not None
209
- RedisManager.init(settings.redis_dsn)
210
- assert RedisManager.redis is not None
211
- return RedisLockService(RedisManager.redis)
200
+ redis_client = CacheManager.init(cache_settings)
201
+ return RedisLockService(redis_client) # type: ignore
212
202
 
213
203
 
214
204
  provider = CoreProvider()
@@ -9,9 +9,9 @@
9
9
  from typing import ClassVar, Protocol, Self, cast
10
10
 
11
11
  from fastapi_cache import FastAPICache
12
+ from redis import asyncio as aioredis
12
13
 
13
14
  from fast_clean.settings import CoreCacheSettingsSchema
14
- from redis import asyncio as aioredis
15
15
 
16
16
  from .in_memory import InMemoryCacheRepository as InMemoryCacheRepository
17
17
  from .redis import RedisCacheRepository as RedisCacheRepository
@@ -67,7 +67,7 @@ class CacheManager:
67
67
  cache_repository: ClassVar[CacheRepositoryProtocol | None] = None
68
68
 
69
69
  @classmethod
70
- def init(cls, cache_settings: CoreCacheSettingsSchema, redis: aioredis.Redis | None) -> None:
70
+ def init(cls, cache_settings: CoreCacheSettingsSchema):
71
71
  """
72
72
  Инициализируем кеш.
73
73
  """
@@ -77,7 +77,13 @@ class CacheManager:
77
77
  case 'in_memory':
78
78
  cache_backend = InMemoryCacheRepository()
79
79
  case 'redis':
80
- assert redis is not None
81
- cache_backend = RedisCacheRepository(redis)
80
+ if not cache_settings.redis:
81
+ raise ValueError('Redis not configured in settings')
82
+ cache_backend = RedisCacheRepository(
83
+ aioredis.from_url(url=str(cache_settings.redis.dsn), decode_responses=True) # type: ignore
84
+ )
85
+ case _:
86
+ raise ValueError('Cache is not initialized')
82
87
  FastAPICache.init(cache_backend, prefix=cache_settings.prefix)
83
88
  cls.cache_repository = cast(CacheRepositoryProtocol, cache_backend)
89
+ return cls.cache_repository
@@ -6,7 +6,6 @@ from typing import Self
6
6
 
7
7
  from fastapi_cache.backends.redis import RedisBackend
8
8
  from overrides import override
9
-
10
9
  from redis.asyncio.client import Redis
11
10
 
12
11
 
@@ -6,10 +6,11 @@ from collections.abc import AsyncIterator
6
6
  from contextlib import asynccontextmanager
7
7
  from typing import AsyncContextManager, Protocol
8
8
 
9
- from fast_clean.exceptions import LockError
10
9
  from redis import asyncio as aioredis
11
10
  from redis.exceptions import LockError as AIORedisLockError
12
11
 
12
+ from fast_clean.exceptions import LockError
13
+
13
14
 
14
15
  class LockServiceProtocol(Protocol):
15
16
  """
fast_clean/settings.py CHANGED
@@ -39,6 +39,10 @@ class CoreDbSettingsSchema(BaseModel):
39
39
  return f'{self.provider}://{self.user}:{self.password}@{self.host}:{self.port}/{self.name}'
40
40
 
41
41
 
42
+ class CoreRedisSettingsSchema(BaseModel):
43
+ dsn: RedisDsn
44
+
45
+
42
46
  class CoreCacheSettingsSchema(BaseModel):
43
47
  """
44
48
  Схема настроек кеша.
@@ -48,6 +52,8 @@ class CoreCacheSettingsSchema(BaseModel):
48
52
 
49
53
  prefix: str
50
54
 
55
+ redis: CoreRedisSettingsSchema | None = None
56
+
51
57
 
52
58
  class CoreS3SettingsSchema(BaseModel):
53
59
  """
@@ -178,7 +184,6 @@ class CoreSettingsSchema(BaseSettingsSchema):
178
184
  base_dir: Path = Path(os.getcwd())
179
185
  secret_key: str
180
186
  cors_origins: Annotated[list[str], Field(default_factory=list)]
181
- redis_dsn: RedisDsn | None = None
182
187
  sentry_dsn: str | None = None
183
188
 
184
189
  model_config = SettingsConfigDict(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fast-clean
3
- Version: 1.4.0
3
+ Version: 1.4.1
4
4
  Summary: FastAPI Clean Architecture implementation
5
5
  Author-email: Luferov Victor <luferovvs@yandex.ru>, Orlov Artem <squakrazv@yandex.ru>, Kashapov Rustam <hardtechnik91@gmail.com>
6
6
  Requires-Python: >=3.13
@@ -2,15 +2,14 @@ fast_clean/__init__.py,sha256=sT4tb75t5PXws8W_7wpA0jNtNxkWPFLAMrPlDGS7RHw,51
2
2
  fast_clean/broker.py,sha256=CHnL4Jd6jF5gKgtUXi33j9QFG2EUM4uqhVqdLuxIrZs,4474
3
3
  fast_clean/container.py,sha256=E1e0H1JqGOacH4uBNwkjTDXYhzN56yZi0AmWXQ3DkEQ,3535
4
4
  fast_clean/db.py,sha256=uZHXXHdLstqhyzGtBL5Z7VvXwIe6mxuPOUheJEzSMyM,5776
5
- fast_clean/depends.py,sha256=e5KQlvVPDPZrMaZBWAPOuLCt-HO7b9NA4UTMaTsB1Y8,7807
5
+ fast_clean/depends.py,sha256=InU6x629CyRGskMbA4LzX5btzw_a1YeVwUckBH5tJNg,7330
6
6
  fast_clean/enums.py,sha256=lPhC_2_r6YFby7Mq-9u_JSiuyZ0e57F2VxBfUwnBZ18,826
7
7
  fast_clean/exceptions.py,sha256=Sp-k-a5z1Gedu0slzj1-rORnr4GP1FXDHKCKRaJq-7o,9485
8
8
  fast_clean/loggers.py,sha256=hVvZSDMMxYnK-p_yyjd4R7SyHpmxQF3eKQEeMu9Q-jo,705
9
9
  fast_clean/middleware.py,sha256=p0Tv_qu89ZQtzKZ10tNepArJyHlFX2II9UmivGWnycw,1037
10
10
  fast_clean/models.py,sha256=H7-Hk3gZP9i2TiJHu0u2Nex76c8ZbDhMR4lF41_PMyI,1057
11
11
  fast_clean/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- fast_clean/redis.py,sha256=H_SLnDhY_ute8pYHdhIypUGlCwMcVfFA4S2j8vLUph0,578
13
- fast_clean/settings.py,sha256=YgmdhW38quBHQty254Pv-vFZ5eGbl__VQ1lIgoVg8kI,4864
12
+ fast_clean/settings.py,sha256=Ox2aDEOxw4LgrszCNpUMNlxCqozc6kcv7406786ADAw,4938
14
13
  fast_clean/cli/__init__.py,sha256=m8n09uN47JGtAfgWVbXCJOxpzlrUazogqtLo6xPWe3s,181
15
14
  fast_clean/cli/cryptography.py,sha256=ACaYAOn4KEKIdsTuCYkX1m6g2YpMczNCjJcVfLE2Rzo,1936
16
15
  fast_clean/cli/load_seed.py,sha256=Tm5_r_myrC5dl_WyC6Bx2WKFAkfLf-Pch4ZK6zWN2Qg,867
@@ -27,9 +26,9 @@ fast_clean/contrib/monitoring/router.py,sha256=94gffX34VE_Yb6TLaQOP4YyXDQsClzOn4
27
26
  fast_clean/contrib/sqlalchemy_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
27
  fast_clean/contrib/sqlalchemy_utils/utils.py,sha256=5xktmJlQifGpIXMruhe7qofEEu_ExncBTUmlrtFK1YQ,1061
29
28
  fast_clean/repositories/__init__.py,sha256=mHJ6CW1fYkkiSnnYiO3GRAa5YVCPN1otOOKkjbutuhs,1753
30
- fast_clean/repositories/cache/__init__.py,sha256=pD7qIS6H8DrnhOptJiXrlGcWYUCIU3VmVQCLccyxx4Q,2511
29
+ fast_clean/repositories/cache/__init__.py,sha256=aVl1ReoU0doH1i78-Ef8rS-LaVQacF0SS9xLFWzmcgQ,2811
31
30
  fast_clean/repositories/cache/in_memory.py,sha256=Hb68UrTmQozALcyLrmYPBIfJfi67NvsCTDe1RfqwBHQ,2259
32
- fast_clean/repositories/cache/redis.py,sha256=UjrA2CXQtMfHTpowz6Ot952y73YjTEr6zJlBbWblaws,1908
31
+ fast_clean/repositories/cache/redis.py,sha256=-iX6x-sfXj-pDYfcRIyKjq9nCjnlRQKeJtfeMmDpT-4,1907
33
32
  fast_clean/repositories/crud/__init__.py,sha256=z_-zY3esEbUEHSGb9WInU-vvRuTpTu4M-Qe5UhCN0Pc,4359
34
33
  fast_clean/repositories/crud/db.py,sha256=wyvDvEjvncfSVHlaguhrgCP7wIsiKRoGZEesxHzDVHI,23212
35
34
  fast_clean/repositories/crud/in_memory.py,sha256=37VBQJTIV4z1_Om9DhYqpa1t98hGGhY8gumoyV-fhDg,13172
@@ -51,7 +50,7 @@ fast_clean/schemas/pagination.py,sha256=GEQ-Tbhx6xkMMXhDNWrTEhPv8IdnAOJxH2P1tscm
51
50
  fast_clean/schemas/repository.py,sha256=ASxMJb23H3zwavr7P0_ZpCWZX7FjqAuC75qAIYqejvQ,889
52
51
  fast_clean/schemas/request_response.py,sha256=i4HTpjelWl4DxJ1sQaeanTWB_PThlhVJRhtMMGqRAiQ,693
53
52
  fast_clean/services/__init__.py,sha256=Lvdb5ZibRGwoMn_WENrk9wERUViTsPrU8E_71XtPFJc,617
54
- fast_clean/services/lock.py,sha256=SLF9_wRx3rgHMw829XwflJgAlGJyXj57o4iVPvGwe78,1653
53
+ fast_clean/services/lock.py,sha256=SlO-wkULBtm9X7jvtUTiEpmDWuiNTscMD-73PPlmI0o,1654
55
54
  fast_clean/services/seed.py,sha256=M0yA2I5z-jLM2UcW_x7287mwIFW5Vt0fPFaplakGFc0,2836
56
55
  fast_clean/services/transaction.py,sha256=djXR6e6ukgpBXDbVmU095MvRJAIqdOPMgAcege52Qxg,762
57
56
  fast_clean/services/cryptography/__init__.py,sha256=XK9-z6HT1Jgfc4-IpNY6fZihjW2dqeO83cz5ZvjJIbo,1559
@@ -67,7 +66,7 @@ fast_clean/utils/time.py,sha256=nvavbtG4zR_gkrGSbsqKAsBdePxO3LuTeoISbFZIgn0,307
67
66
  fast_clean/utils/toml.py,sha256=NbP7EfgKNYQ18LH8Hc-DmY1gks92bUSBW3D3-tMrY4E,737
68
67
  fast_clean/utils/type_converters.py,sha256=bMEJeoQB9Q6Qok1-ppn4Ii8ZpIkZwJbD2IzCydSStHw,523
69
68
  fast_clean/utils/typer.py,sha256=1O7BsNGn68bBzNbj0-Ycfhv35WpLzwvYTKn510YNXQQ,663
70
- fast_clean-1.4.0.dist-info/METADATA,sha256=ltPh_moagnnuYT0IIVzx_hxD4I3PddBCpKp27xiy45s,1200
71
- fast_clean-1.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
72
- fast_clean-1.4.0.dist-info/top_level.txt,sha256=QfsGs-QLmPCZWWPFOukD0zhMnokH68FoO2KeObl6ZIA,11
73
- fast_clean-1.4.0.dist-info/RECORD,,
69
+ fast_clean-1.4.1.dist-info/METADATA,sha256=mXmRInGHMorgthwk9OC2GgE0O3zeelJbj5j9_JvG8pA,1200
70
+ fast_clean-1.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
+ fast_clean-1.4.1.dist-info/top_level.txt,sha256=QfsGs-QLmPCZWWPFOukD0zhMnokH68FoO2KeObl6ZIA,11
72
+ fast_clean-1.4.1.dist-info/RECORD,,
fast_clean/redis.py DELETED
@@ -1,23 +0,0 @@
1
- """
2
- Модуль, содержащий функционал, связанный с Redis.
3
- """
4
-
5
- from pydantic import RedisDsn
6
-
7
- from redis import asyncio as aioredis
8
-
9
-
10
- class RedisManager:
11
- """
12
- Менеджер для управления клиентом Redis.
13
- """
14
-
15
- redis: aioredis.Redis | None = None
16
-
17
- @classmethod
18
- def init(cls, redis_dsn: RedisDsn) -> None:
19
- """
20
- Инициализируем клиент Redis.
21
- """
22
- if cls.redis is None:
23
- cls.redis = aioredis.from_url(url=str(redis_dsn), decode_responses=True)