rb-commons 0.1.23__tar.gz → 0.2.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.
Files changed (27) hide show
  1. {rb_commons-0.1.23 → rb-commons-0.2.2}/PKG-INFO +4 -12
  2. rb-commons-0.2.2/rb_commons/broker/consumer.py +29 -0
  3. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/configs/config.py +4 -0
  4. rb-commons-0.2.2/rb_commons/configs/rabbitmq.py +26 -0
  5. rb-commons-0.2.2/rb_commons/utils/__init__.py +0 -0
  6. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons.egg-info/PKG-INFO +4 -12
  7. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons.egg-info/SOURCES.txt +3 -0
  8. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons.egg-info/requires.txt +2 -1
  9. {rb_commons-0.1.23 → rb-commons-0.2.2}/setup.py +4 -3
  10. {rb_commons-0.1.23 → rb-commons-0.2.2}/README.md +0 -0
  11. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/__init__.py +0 -0
  12. {rb_commons-0.1.23/rb_commons/configs → rb-commons-0.2.2/rb_commons/broker}/__init__.py +0 -0
  13. {rb_commons-0.1.23/rb_commons/http → rb-commons-0.2.2/rb_commons/configs}/__init__.py +0 -0
  14. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/configs/injections.py +0 -0
  15. {rb_commons-0.1.23/rb_commons/orm → rb-commons-0.2.2/rb_commons/http}/__init__.py +0 -0
  16. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/http/exceptions.py +0 -0
  17. {rb_commons-0.1.23/rb_commons/permissions → rb-commons-0.2.2/rb_commons/orm}/__init__.py +0 -0
  18. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/orm/exceptions.py +0 -0
  19. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/orm/managers.py +0 -0
  20. {rb_commons-0.1.23/rb_commons/schemes → rb-commons-0.2.2/rb_commons/permissions}/__init__.py +0 -0
  21. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/permissions/role_permissions.py +0 -0
  22. {rb_commons-0.1.23/rb_commons/utils → rb-commons-0.2.2/rb_commons/schemes}/__init__.py +0 -0
  23. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/schemes/jwt.py +0 -0
  24. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons/utils/media.py +0 -0
  25. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons.egg-info/dependency_links.txt +0 -0
  26. {rb_commons-0.1.23 → rb-commons-0.2.2}/rb_commons.egg-info/top_level.txt +0 -0
  27. {rb_commons-0.1.23 → rb-commons-0.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.1
2
2
  Name: rb-commons
3
- Version: 0.1.23
3
+ Version: 0.2.2
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -12,20 +12,12 @@ Requires-Python: >=3.11
12
12
  Description-Content-Type: text/markdown
13
13
  Requires-Dist: annotated-types==0.7.0
14
14
  Requires-Dist: greenlet==3.1.1
15
- Requires-Dist: pydantic==2.10.4
15
+ Requires-Dist: pydantic<3.0.0,>=1.7.4
16
16
  Requires-Dist: PyJWT==2.10.1
17
17
  Requires-Dist: python-dotenv==1.0.1
18
18
  Requires-Dist: SQLAlchemy==2.0.36
19
19
  Requires-Dist: fastapi<0.120.0,>=0.115.6
20
- Dynamic: author
21
- Dynamic: author-email
22
- Dynamic: classifier
23
- Dynamic: description
24
- Dynamic: description-content-type
25
- Dynamic: home-page
26
- Dynamic: requires-dist
27
- Dynamic: requires-python
28
- Dynamic: summary
20
+ Requires-Dist: aio-pika==9.5.5
29
21
 
30
22
  # RB-Commons
31
23
 
@@ -0,0 +1,29 @@
1
+ from aio_pika import ExchangeType, IncomingMessage
2
+ from rb_commons.configs.rabbitmq import RabbitMQConnection
3
+
4
+
5
+ class BaseRabbitMQConsumer:
6
+ def __init__(self, exchange_name: str, queue_name: str, routing_key: str):
7
+ self.exchange_name = exchange_name
8
+ self.queue_name = queue_name
9
+ self.routing_key = routing_key
10
+
11
+ async def setup(self, channel):
12
+ exchange = await channel.declare_exchange(self.exchange_name, ExchangeType.DIRECT, durable=True)
13
+ queue = await channel.declare_queue(self.queue_name, durable=True)
14
+ await queue.bind(exchange, routing_key=self.routing_key)
15
+ return queue
16
+
17
+ async def consume(self):
18
+ async with RabbitMQConnection.get_channel() as channel:
19
+ queue = await self.setup(channel)
20
+ async with queue.iterator() as queue_iter:
21
+ async for message in queue_iter:
22
+ await self.process_message(message)
23
+
24
+ async def process_message(self, message: IncomingMessage):
25
+ async with message.process():
26
+ await self.handle_message(message.body.decode())
27
+
28
+ async def handle_message(self, body: str):
29
+ raise NotImplementedError("This method should be overridden by subclasses.")
@@ -20,6 +20,10 @@ class CommonConfigs(BaseSettings):
20
20
  POSTGRES_DB: Optional[str] = None
21
21
  DB_ALEMBIC_URL: Optional[str] = None
22
22
 
23
+ # Broker
24
+
25
+ RABBITMQ_URL: Optional[str] = None
26
+
23
27
  DIGITALOCEAN_STORAGE_BUCKET_NAME: Optional[str] = None
24
28
  DIGITALOCEAN_S3_ENDPOINT_URL: Optional[str] = None
25
29
 
@@ -0,0 +1,26 @@
1
+ from contextlib import asynccontextmanager
2
+ from aio_pika import connect_robust, Message, ExchangeType
3
+ from rb_commons.configs.config import configs
4
+
5
+ class RabbitMQConnection:
6
+ _connection = None
7
+ _channel = None
8
+
9
+ @classmethod
10
+ @asynccontextmanager
11
+ async def get_channel(cls):
12
+ if not cls._connection:
13
+ cls._connection = await connect_robust(configs.RABBITMQ_URL)
14
+ cls._channel = await cls._connection.channel()
15
+
16
+ try:
17
+ yield cls._channel
18
+ finally:
19
+ pass
20
+
21
+ @classmethod
22
+ async def close(cls):
23
+ if cls._connection:
24
+ await cls._connection.close()
25
+ cls._connection = None
26
+ cls._channel = None
File without changes
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.1
2
2
  Name: rb-commons
3
- Version: 0.1.23
3
+ Version: 0.2.2
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -12,20 +12,12 @@ Requires-Python: >=3.11
12
12
  Description-Content-Type: text/markdown
13
13
  Requires-Dist: annotated-types==0.7.0
14
14
  Requires-Dist: greenlet==3.1.1
15
- Requires-Dist: pydantic==2.10.4
15
+ Requires-Dist: pydantic<3.0.0,>=1.7.4
16
16
  Requires-Dist: PyJWT==2.10.1
17
17
  Requires-Dist: python-dotenv==1.0.1
18
18
  Requires-Dist: SQLAlchemy==2.0.36
19
19
  Requires-Dist: fastapi<0.120.0,>=0.115.6
20
- Dynamic: author
21
- Dynamic: author-email
22
- Dynamic: classifier
23
- Dynamic: description
24
- Dynamic: description-content-type
25
- Dynamic: home-page
26
- Dynamic: requires-dist
27
- Dynamic: requires-python
28
- Dynamic: summary
20
+ Requires-Dist: aio-pika==9.5.5
29
21
 
30
22
  # RB-Commons
31
23
 
@@ -6,9 +6,12 @@ rb_commons.egg-info/SOURCES.txt
6
6
  rb_commons.egg-info/dependency_links.txt
7
7
  rb_commons.egg-info/requires.txt
8
8
  rb_commons.egg-info/top_level.txt
9
+ rb_commons/broker/__init__.py
10
+ rb_commons/broker/consumer.py
9
11
  rb_commons/configs/__init__.py
10
12
  rb_commons/configs/config.py
11
13
  rb_commons/configs/injections.py
14
+ rb_commons/configs/rabbitmq.py
12
15
  rb_commons/http/__init__.py
13
16
  rb_commons/http/exceptions.py
14
17
  rb_commons/orm/__init__.py
@@ -1,7 +1,8 @@
1
1
  annotated-types==0.7.0
2
2
  greenlet==3.1.1
3
- pydantic==2.10.4
3
+ pydantic<3.0.0,>=1.7.4
4
4
  PyJWT==2.10.1
5
5
  python-dotenv==1.0.1
6
6
  SQLAlchemy==2.0.36
7
7
  fastapi<0.120.0,>=0.115.6
8
+ aio-pika==9.5.5
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="rb-commons",
8
- version="0.1.23",
8
+ version="0.2.2",
9
9
  author="Abdulvoris",
10
10
  author_email="erkinovabdulvoris101@gmail.com",
11
11
  description="Commons of project and simplified orm based on sqlalchemy.",
@@ -22,10 +22,11 @@ setup(
22
22
  install_requires=[
23
23
  "annotated-types==0.7.0",
24
24
  "greenlet==3.1.1",
25
- "pydantic==2.10.4",
25
+ "pydantic>=1.7.4,<3.0.0",
26
26
  "PyJWT==2.10.1",
27
27
  "python-dotenv==1.0.1",
28
28
  "SQLAlchemy==2.0.36",
29
- "fastapi>=0.115.6,<0.120.0"
29
+ "fastapi>=0.115.6,<0.120.0",
30
+ "aio-pika==9.5.5"
30
31
  ],
31
32
  )
File without changes
File without changes