documente_shared 0.1.85__py3-none-any.whl → 0.1.87__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 documente_shared might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ import pytz
2
+ from datetime import datetime
3
+
4
+
5
+
6
+ def utc_now() -> datetime:
7
+ return datetime.now(tz=pytz.utc)
@@ -17,6 +17,7 @@ class ProcessingCaseFilters(object):
17
17
  statuses: List[ProcessingStatus] = None
18
18
  case_types: List[ProcessingCaseType] = None
19
19
  include_archived: bool = False
20
+ tenant_slug: Optional[str] = None
20
21
 
21
22
  def __post_init__(self):
22
23
  self.case_ids = self.case_ids or []
@@ -20,6 +20,7 @@ class ProcessingCaseItemFilters(object):
20
20
  statuses: List[ProcessingStatus] = None
21
21
  document_types: List[ProcessingDocumentType] = None
22
22
  include_archived: bool = False
23
+ tenant_slug: Optional[str] = None
23
24
 
24
25
  def __post_init__(self):
25
26
  self.statuses = self.statuses or []
@@ -0,0 +1,25 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional
3
+
4
+
5
+ @dataclass
6
+ class ScalingRequirements(object):
7
+ documents: Optional[int] = 0
8
+ processing_cases: Optional[int] = 0
9
+ processing_case_items: Optional[int] = 0
10
+
11
+ @property
12
+ def to_dict(self):
13
+ return {
14
+ "documents": self.documents,
15
+ "processing_cases": self.processing_cases,
16
+ "processing_case_items": self.processing_case_items,
17
+ }
18
+
19
+ @classmethod
20
+ def from_dict(cls, data: dict) -> "ScalingRequirements":
21
+ return cls(
22
+ documents=data.get("documents", 0),
23
+ processing_cases=data.get("processing_cases", 0),
24
+ processing_case_items=data.get("processing_case_items", 0),
25
+ )
@@ -110,3 +110,10 @@ class ProcessingType(BaseEnum):
110
110
  @property
111
111
  def is_processing_case(self):
112
112
  return self == ProcessingType.PROCESSING_CASE
113
+
114
+
115
+ class TaskResultStatus(BaseEnum):
116
+ PENDING = "PENDING"
117
+ SUCCESS = "SUCCESS"
118
+ IN_PROGRESS = "IN_PROGRESS"
119
+ FAILURE = "FAILURE"
File without changes
@@ -0,0 +1,10 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from documente_shared.domain.entities.scaling import ScalingRequirements
4
+
5
+
6
+ class ScalingService(ABC):
7
+
8
+ @abstractmethod
9
+ def get_scaling_requirements(self) -> ScalingRequirements:
10
+ raise NotImplementedError
@@ -20,5 +20,5 @@ class ProcessingCaseRepository(ABC):
20
20
  raise NotImplementedError
21
21
 
22
22
  @abstractmethod
23
- def filter(self, tenant_slug: str, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
23
+ def filter(self, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
24
24
  raise NotImplementedError
@@ -26,7 +26,6 @@ class ProcessingCaseItemRepository(ABC):
26
26
  @abstractmethod
27
27
  def filter(
28
28
  self,
29
- tenant_slug: str,
30
29
  filters: ProcessingCaseItemFilters,
31
30
  ) -> List[ProcessingCaseItem]:
32
31
  raise NotImplementedError
@@ -0,0 +1,14 @@
1
+ import json
2
+ import boto3
3
+
4
+
5
+ def invoke_lambda(function_name: str, payload: dict) -> dict | list | None:
6
+ client = boto3.client('lambda')
7
+
8
+ response = client.invoke(
9
+ FunctionName=function_name,
10
+ InvocationType='RequestResponse',
11
+ Payload=json.dumps(payload),
12
+ )
13
+
14
+ return json.loads(response['Payload'].read().decode('utf-8'))
@@ -26,7 +26,7 @@ class DynamoProcessingCaseRepository(
26
26
  def remove(self, instance: ProcessingCase):
27
27
  self.delete(key={'uuid': instance.uuid})
28
28
 
29
- def filter(self, tenant_slug: str, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
29
+ def filter(self, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
30
30
  items = []
31
31
 
32
32
  for status in filters.statuses:
@@ -34,7 +34,6 @@ class DynamoProcessingCaseItemRepository(
34
34
 
35
35
  def filter(
36
36
  self,
37
- tenant_slug: str,
38
37
  filters: ProcessingCaseItemFilters,
39
38
  ) -> List[ProcessingCaseItem]:
40
39
  items = []
@@ -50,4 +49,4 @@ class DynamoProcessingCaseItemRepository(
50
49
  return [
51
50
  ProcessingCaseItem.from_dict(item)
52
51
  for item in items
53
- ]
52
+ ]
@@ -34,11 +34,11 @@ class HttpProcessingCaseRepository(
34
34
  def remove(self, instance: ProcessingCase):
35
35
  self.session.delete(f"{self.api_url}/v1/processing-cases/{instance.uuid}/")
36
36
 
37
- def filter(self, tenant_slug: str, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
37
+ def filter(self, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
38
38
  response = self.session.get(
39
39
  url=f"{self.api_url}/v1/processing-cases/",
40
40
  headers={
41
- "X-Tenant": tenant_slug,
41
+ "X-Tenant": filters.tenant_slug,
42
42
  }
43
43
  )
44
44
  if response.status_code == 200:
@@ -49,6 +49,7 @@ class HttpProcessingCaseRepository(
49
49
  ]
50
50
  return []
51
51
 
52
+
52
53
  @classmethod
53
54
  def _build_processing_case(cls, response: Response) -> ProcessingCase:
54
55
  response_json = response.json()
@@ -40,6 +40,18 @@ class HttpProcessingCaseItemRepository(
40
40
  self.session.delete(f"{self.api_url}/v1/processing-case-items/{instance.uuid}/")
41
41
 
42
42
  def filter(
43
+ self,
44
+ filters: ProcessingCaseItemFilters,
45
+ ) -> List[ProcessingCaseItem]:
46
+ response = self.session.get(f"{self.api_url}/v1/processing-case-items/")
47
+ if response.status_code == 200:
48
+ raw_response = response.json()
49
+ return [
50
+ ProcessingCaseItem.from_dict(camel_to_snake(item_data))
51
+ for item_data in raw_response.get('data', [])
52
+ ]
53
+ return []
54
+ def filter_with_tenant(
43
55
  self,
44
56
  tenant_slug: str,
45
57
  filters: ProcessingCaseItemFilters,
File without changes
@@ -0,0 +1,24 @@
1
+ from dataclasses import dataclass
2
+
3
+ from loguru import logger
4
+
5
+ from documente_shared.application.payloads import camel_to_snake
6
+ from documente_shared.domain.entities.scaling import ScalingRequirements
7
+ from documente_shared.domain.interfaces.scaling import ScalingService
8
+ from documente_shared.infrastructure.documente_client import DocumenteClientMixin
9
+
10
+
11
+ @dataclass
12
+ class HttpScalingService(
13
+ DocumenteClientMixin,
14
+ ScalingService,
15
+ ):
16
+ def get_scaling_requirements(self) -> ScalingRequirements:
17
+ response = self.session.get(f"{self.api_url}/v1/scaling-requirements/")
18
+ if response.status_code == 200:
19
+ return ScalingRequirements.from_dict(
20
+ data=camel_to_snake(response.json())
21
+ )
22
+
23
+ logger.warning(f'Error getting scaling requirements: {response.text}')
24
+ return ScalingRequirements()
File without changes
@@ -0,0 +1,16 @@
1
+ from dataclasses import dataclass
2
+
3
+ from documente_shared.application.dates import utc_now
4
+ from documente_shared.domain.enums.common import TaskResultStatus
5
+
6
+
7
+ @dataclass
8
+ class TaskResultPresenter(object):
9
+ status: TaskResultStatus = TaskResultStatus.SUCCESS
10
+
11
+ @property
12
+ def to_dict(self) -> dict:
13
+ return {
14
+ "status": str(self.status),
15
+ "completed_at": utc_now().isoformat(),
16
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.85
3
+ Version: 0.1.87
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: boto3 (>=1.37.19,<2.0.0)
15
15
  Requires-Dist: botocore (>=1.37.19,<2.0.0)
16
+ Requires-Dist: loguru (>=0.7.3,<0.8.0)
16
17
  Requires-Dist: pytz (>=2025.2,<2026.0)
17
18
  Requires-Dist: requests (>=2.32.3,<3.0.0)
18
19
  Requires-Dist: sentry-sdk (>=2.19.2,<3.0.0)
@@ -1,5 +1,6 @@
1
1
  documente_shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  documente_shared/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ documente_shared/application/dates.py,sha256=uExNddWmX9VEX_u420JGoC7fL-ieJ4956I0aw_WX3sQ,109
3
4
  documente_shared/application/digest.py,sha256=Um6E8WfFri2_lly4RFWydJyvSfPZGFcOX-opEOzDCWc,172
4
5
  documente_shared/application/exceptions.py,sha256=lQM8m7wmI9OTLGva0gd7s7YT7ldaTk_Ln4t32PpzNf8,654
5
6
  documente_shared/application/files.py,sha256=ADiWi6Mk3YQGx3boGsDqdb5wk8qmabkGRy7bhNFa1OY,649
@@ -15,30 +16,38 @@ documente_shared/domain/entities/document.py,sha256=AthTUyA-QZE3WAT7lMoKVr_Z8mO_
15
16
  documente_shared/domain/entities/document_metadata.py,sha256=ygyFIC5qwxlm8DUM5kvVFny9zJfPQS8vNLM2br5XsQ8,2353
16
17
  documente_shared/domain/entities/in_memory_result.py,sha256=0sLNUrovKFQx4M-E9e4DrAiVgch2i4AKA-9BQBRaeI8,1482
17
18
  documente_shared/domain/entities/processing_case.py,sha256=_UTMCSQjTSttNWa-NC7eWJITkNm6NZuGGT9gNm9D1mA,4970
18
- documente_shared/domain/entities/processing_case_filters.py,sha256=FgyxB4mQb0nEGjIbUB9OiazkKL4yHRRC6bvmjD5NT8k,1915
19
+ documente_shared/domain/entities/processing_case_filters.py,sha256=harKyu7QEuL1bI_Z8_UxkVCMo5r9vHeNHyi_Ja07vjs,1953
19
20
  documente_shared/domain/entities/processing_case_item.py,sha256=U_g99AJdlRRJpJ0NPfmXzlr2x04l5hc53oNLxx_Q7XQ,9734
20
- documente_shared/domain/entities/processing_case_item_filters.py,sha256=-cAQTSWOepMMcGCBg2X3dd0W_8XHuBTlvOB1d-3sVVM,1971
21
+ documente_shared/domain/entities/processing_case_item_filters.py,sha256=R_AvDCB496Lww1qn2OwtltqULKE3IpcJB0ejnmRkg7Q,2009
21
22
  documente_shared/domain/entities/processing_event.py,sha256=AMkW4dJjW6ss-uvDeWzVMBIJtax8JNWy-zPo1R-TiWY,1963
23
+ documente_shared/domain/entities/scaling.py,sha256=Me1z3X-5NjzPMX-TBQ4xHwE_44tIJegi1QSCHQRNtx4,745
22
24
  documente_shared/domain/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- documente_shared/domain/enums/common.py,sha256=yoq__M53bCCf7B2tbOGdOpieYvGpiJ69s6T0FqvLUII,2687
25
+ documente_shared/domain/enums/common.py,sha256=wJWYhh98sdCGL_1WodhYLpoT_IYTzkTDOexclpaIM-0,2827
24
26
  documente_shared/domain/enums/document.py,sha256=QwvckW-VJBSujllIVloKlZUh1pI5UnX4oueYbV5CYGw,3205
25
27
  documente_shared/domain/enums/processing_case.py,sha256=LhFhcoWlockxcpplsVdC6M2kpXn7sOdzQySf24wFhx8,1572
28
+ documente_shared/domain/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ documente_shared/domain/interfaces/scaling.py,sha256=0Mefc_GVNdyRtAdkxlnvQuXrmM4Yx7VOJQCfVZOgISQ,257
26
30
  documente_shared/domain/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
31
  documente_shared/domain/repositories/document.py,sha256=vJzr6c92gqBzyhaEdjrvnoneKRrWmJ0AsvocPnhxiLU,767
28
- documente_shared/domain/repositories/processing_case.py,sha256=9jGpnUnXaDgQE1ZKiet7zDVCc7wVvHUrcPOeacebb3s,796
29
- documente_shared/domain/repositories/processing_case_item.py,sha256=gPZaQCMYlD6vlnEt6cVIqRmi1K-JWvmDx1f74nd97Cs,974
32
+ documente_shared/domain/repositories/processing_case.py,sha256=QcY0LumRokRLmL3IWkOZTgN-LQ-Kku5_v7DWujO1Dfw,778
33
+ documente_shared/domain/repositories/processing_case_item.py,sha256=uBgJN2fJnZDcKUk018P_Fv25dQRZD5FBxFxsCQNaGAQ,948
30
34
  documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
35
  documente_shared/infrastructure/documente_client.py,sha256=paO66zNelDyA6D6iqTXXFVQ9ERRZoJCGWR3T3hySsaM,503
32
36
  documente_shared/infrastructure/dynamo_table.py,sha256=TMQbcuty7wjDMbuhI8PbT0IGXelgELsNTtqTEQeZ824,2112
37
+ documente_shared/infrastructure/lambdas.py,sha256=sGgkw7Mhvuq2TpbW_RNdf5JvQnuzxWYH6gPOVtQ4DtE,357
33
38
  documente_shared/infrastructure/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
39
  documente_shared/infrastructure/repositories/dynamo_document.py,sha256=_Yp4gtA-n-hJ2w2wAM5BMCs2Mf46Q2Kq3eHqlxudkL4,1443
35
- documente_shared/infrastructure/repositories/dynamo_processing_case.py,sha256=IoIHtlaEe4G5TqIV9IvG45a3HRBVHLfNC9sSgQjabUk,1464
36
- documente_shared/infrastructure/repositories/dynamo_processing_case_item.py,sha256=4guM8V3YfP7kzYcuVWunGJGmXi0kSSUW8otks39g1vs,1754
40
+ documente_shared/infrastructure/repositories/dynamo_processing_case.py,sha256=jkTVHThKHshLI53OV7ivK-WchFoAZTnaXlgh_1OX52k,1446
41
+ documente_shared/infrastructure/repositories/dynamo_processing_case_item.py,sha256=B2ElsASpXNRkwwjdCqXyvDU-LBrLNdwPfHLMvvG9c-Y,1729
37
42
  documente_shared/infrastructure/repositories/http_document_processing.py,sha256=7n4lHgpN17CCr4_Dz9WRbsXeb4FDMJZNDUshFipA1B8,2179
38
- documente_shared/infrastructure/repositories/http_processing_case.py,sha256=FcOnzPUu-iWjj6O5syzqN61u6xogMoQMfbSnALqeK-c,2258
39
- documente_shared/infrastructure/repositories/http_processing_case_item.py,sha256=babWakDZfHxWgB1OUwZsPTr8nhDwC-CDBn-vYtgUtUM,2494
43
+ documente_shared/infrastructure/repositories/http_processing_case.py,sha256=n1NXJtROTfet2QCKSNnQtLmcNgkJDo6q0Hq48FSpwEU,2249
44
+ documente_shared/infrastructure/repositories/http_processing_case_item.py,sha256=cCi7uo1aHPhroxRRlFOhIUgGkY_S2dvWl1DAVr_maxw,2966
40
45
  documente_shared/infrastructure/s3_bucket.py,sha256=vT_yN42RFQXubtUn8ln-j13Os_-25UGClVtXg5Bkv6I,1932
46
+ documente_shared/infrastructure/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
+ documente_shared/infrastructure/services/http_scaling.py,sha256=SK0vReNGXzfN2yKNiYq9u1fvDECU5dHynq5507i7fgI,856
41
48
  documente_shared/infrastructure/sqs_queue.py,sha256=KZWeHZ9zmXmrxoNpOQX7GEdDhZ1knbPXgwSwFwJblGg,1504
42
- documente_shared-0.1.85.dist-info/METADATA,sha256=On4dTXDR9MF1K2P2FjhW_OeCNOLfBQW0XZT2hI8t5Zg,881
43
- documente_shared-0.1.85.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
44
- documente_shared-0.1.85.dist-info/RECORD,,
49
+ documente_shared/presentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
+ documente_shared/presentation/presenters.py,sha256=GGAEwefmjCIVepsUA2oZOVLxXbhhiISPM0Jgt6dT6O0,423
51
+ documente_shared-0.1.87.dist-info/METADATA,sha256=zTsM418cXINfRJx1HAF_JUXqd7Pr8mYEkcuXPt8Ah5A,920
52
+ documente_shared-0.1.87.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
53
+ documente_shared-0.1.87.dist-info/RECORD,,