documente_shared 0.1.84__py3-none-any.whl → 0.1.86__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)
@@ -1,3 +1,5 @@
1
+ from typing import List
2
+
1
3
  from documente_shared.domain.base_enum import BaseEnum
2
4
 
3
5
 
@@ -45,6 +47,21 @@ class ProcessingStatus(BaseEnum):
45
47
  CANCELLED = 'CANCELLED'
46
48
  IN_REVIEW = 'IN_REVIEW'
47
49
 
50
+ @property
51
+ def procesable_statuses(self) -> List['ProcessingStatus']:
52
+ return [
53
+ ProcessingStatus.PENDING,
54
+ ProcessingStatus.ENQUEUED,
55
+ ProcessingStatus.PROCESSING,
56
+ ]
57
+
58
+ @property
59
+ def final_statuses(self) -> List['ProcessingStatus']:
60
+ return [
61
+ ProcessingStatus.COMPLETED,
62
+ ProcessingStatus.FAILED,
63
+ ]
64
+
48
65
  @property
49
66
  def is_pending(self):
50
67
  return self == ProcessingStatus.PENDING
@@ -93,3 +110,10 @@ class ProcessingType(BaseEnum):
93
110
  @property
94
111
  def is_processing_case(self):
95
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"
@@ -1,3 +1,5 @@
1
+ from typing import List
2
+
1
3
  from documente_shared.domain.base_enum import BaseEnum
2
4
 
3
5
 
@@ -12,6 +14,57 @@ class DocumentProcessingStatus(BaseEnum):
12
14
  CANCELLED = 'CANCELLED'
13
15
  IN_REVIEW = 'IN_REVIEW'
14
16
 
17
+ @property
18
+ def procesable_statuses(self) -> List['DocumentProcessingStatus']:
19
+ return [
20
+ DocumentProcessingStatus.PENDING,
21
+ DocumentProcessingStatus.ENQUEUED,
22
+ DocumentProcessingStatus.PROCESSING,
23
+ ]
24
+
25
+ @property
26
+ def final_statuses(self) -> List['DocumentProcessingStatus']:
27
+ return [
28
+ DocumentProcessingStatus.COMPLETED,
29
+ DocumentProcessingStatus.FAILED,
30
+ ]
31
+
32
+ @property
33
+ def is_pending(self):
34
+ return self == DocumentProcessingStatus.PENDING
35
+
36
+ @property
37
+ def is_enqueued(self):
38
+ return self == DocumentProcessingStatus.ENQUEUED
39
+
40
+ @property
41
+ def is_processing(self):
42
+ return self == DocumentProcessingStatus.PROCESSING
43
+
44
+ @property
45
+ def is_completed(self):
46
+ return self == DocumentProcessingStatus.COMPLETED
47
+
48
+ @property
49
+ def is_incomplete(self):
50
+ return self == DocumentProcessingStatus.INCOMPLETE
51
+
52
+ @property
53
+ def is_failed(self):
54
+ return self == DocumentProcessingStatus.FAILED
55
+
56
+ @property
57
+ def is_deleted(self):
58
+ return self == DocumentProcessingStatus.DELETED
59
+
60
+ @property
61
+ def is_cancelled(self):
62
+ return self == DocumentProcessingStatus.CANCELLED
63
+
64
+ @property
65
+ def is_in_review(self):
66
+ return self == DocumentProcessingStatus.IN_REVIEW
67
+
15
68
 
16
69
  class DocumentProcessingCategory(BaseEnum):
17
70
  CIRCULAR = 'CIRCULAR'
@@ -18,4 +18,5 @@ class DocumenteClientMixin(object):
18
18
  return {
19
19
  "X-Api-Key": self.api_key,
20
20
  "Content-Type": "application/json"
21
- }
21
+ }
22
+
@@ -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'))
@@ -0,0 +1,51 @@
1
+ from dataclasses import dataclass
2
+ from typing import List, Optional
3
+ from requests import Response
4
+
5
+ from documente_shared.application.payloads import camel_to_snake
6
+ from documente_shared.domain.entities.document import DocumentProcessing
7
+ from documente_shared.domain.enums.document import DocumentProcessingStatus, DocumentProcessingCategory
8
+ from documente_shared.domain.repositories.document import DocumentProcessingRepository
9
+ from documente_shared.infrastructure.documente_client import DocumenteClientMixin
10
+
11
+
12
+ @dataclass
13
+ class HttpDocumentProcessingRepository(
14
+ DocumenteClientMixin,
15
+ DocumentProcessingRepository,
16
+ ):
17
+ def find(self, digest: str) -> Optional[DocumentProcessing]:
18
+ response = self.session.get(f"{self.api_url}/documents/{digest}/")
19
+ if response.status_code == 200:
20
+ return self._build_processing_case(response)
21
+ return None
22
+
23
+ def persist(self, instance: DocumentProcessing) -> DocumentProcessing:
24
+ response = self.session.put(
25
+ url=f"{self.api_url}/documents/{instance.digest}/",
26
+ json=instance.to_simple_dict,
27
+ )
28
+ if response.status_code in [200, 201]:
29
+ raise Exception(f'Error persisting document processing: {response.text}')
30
+ return self._build_processing_case(response)
31
+
32
+ def remove(self, instance: DocumentProcessing):
33
+ self.session.delete(f"{self.api_url}/documents/{instance.digest}/")
34
+
35
+ def filter(self, statuses: List[DocumentProcessingStatus]) -> List[DocumentProcessing]:
36
+ response = self.session.get(f"{self.api_url}/documents/?statuses={statuses}")
37
+ if response.status_code == 200:
38
+ raw_response = response.json()
39
+ return [
40
+ DocumentProcessing.from_dict(camel_to_snake(item['documentProcessing']))
41
+ for item in raw_response.get('data', [])
42
+ ]
43
+ return []
44
+
45
+ @classmethod
46
+ def _build_processing_case(cls, response: Response) -> DocumentProcessing:
47
+ response_json = response.json()
48
+ instance_data = response_json.get('data', {})
49
+ return DocumentProcessing.from_dict(camel_to_snake(instance_data))
50
+
51
+
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.84
3
+ Version: 0.1.86
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -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
@@ -20,24 +21,28 @@ documente_shared/domain/entities/processing_case_item.py,sha256=U_g99AJdlRRJpJ0N
20
21
  documente_shared/domain/entities/processing_case_item_filters.py,sha256=-cAQTSWOepMMcGCBg2X3dd0W_8XHuBTlvOB1d-3sVVM,1971
21
22
  documente_shared/domain/entities/processing_event.py,sha256=AMkW4dJjW6ss-uvDeWzVMBIJtax8JNWy-zPo1R-TiWY,1963
22
23
  documente_shared/domain/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- documente_shared/domain/enums/common.py,sha256=vXldMUPhhWo0PfTgYwDSjI8bur_lYcImZYiV7yAO7DQ,2262
24
- documente_shared/domain/enums/document.py,sha256=NltZA1YVgJ7dVfSQdJFIE0ZUGf9Y-nxNXsVQ6GiPLL4,1827
24
+ documente_shared/domain/enums/common.py,sha256=wJWYhh98sdCGL_1WodhYLpoT_IYTzkTDOexclpaIM-0,2827
25
+ documente_shared/domain/enums/document.py,sha256=QwvckW-VJBSujllIVloKlZUh1pI5UnX4oueYbV5CYGw,3205
25
26
  documente_shared/domain/enums/processing_case.py,sha256=LhFhcoWlockxcpplsVdC6M2kpXn7sOdzQySf24wFhx8,1572
26
27
  documente_shared/domain/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
28
  documente_shared/domain/repositories/document.py,sha256=vJzr6c92gqBzyhaEdjrvnoneKRrWmJ0AsvocPnhxiLU,767
28
29
  documente_shared/domain/repositories/processing_case.py,sha256=9jGpnUnXaDgQE1ZKiet7zDVCc7wVvHUrcPOeacebb3s,796
29
30
  documente_shared/domain/repositories/processing_case_item.py,sha256=gPZaQCMYlD6vlnEt6cVIqRmi1K-JWvmDx1f74nd97Cs,974
30
31
  documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
- documente_shared/infrastructure/documente_client.py,sha256=UjVWs9DKa-yhw5DVbcEs8iJxalHOarusVayi_ob6QhE,494
32
+ documente_shared/infrastructure/documente_client.py,sha256=paO66zNelDyA6D6iqTXXFVQ9ERRZoJCGWR3T3hySsaM,503
32
33
  documente_shared/infrastructure/dynamo_table.py,sha256=TMQbcuty7wjDMbuhI8PbT0IGXelgELsNTtqTEQeZ824,2112
34
+ documente_shared/infrastructure/lambdas.py,sha256=sGgkw7Mhvuq2TpbW_RNdf5JvQnuzxWYH6gPOVtQ4DtE,357
33
35
  documente_shared/infrastructure/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
36
  documente_shared/infrastructure/repositories/dynamo_document.py,sha256=_Yp4gtA-n-hJ2w2wAM5BMCs2Mf46Q2Kq3eHqlxudkL4,1443
35
37
  documente_shared/infrastructure/repositories/dynamo_processing_case.py,sha256=IoIHtlaEe4G5TqIV9IvG45a3HRBVHLfNC9sSgQjabUk,1464
36
38
  documente_shared/infrastructure/repositories/dynamo_processing_case_item.py,sha256=4guM8V3YfP7kzYcuVWunGJGmXi0kSSUW8otks39g1vs,1754
39
+ documente_shared/infrastructure/repositories/http_document_processing.py,sha256=7n4lHgpN17CCr4_Dz9WRbsXeb4FDMJZNDUshFipA1B8,2179
37
40
  documente_shared/infrastructure/repositories/http_processing_case.py,sha256=FcOnzPUu-iWjj6O5syzqN61u6xogMoQMfbSnALqeK-c,2258
38
41
  documente_shared/infrastructure/repositories/http_processing_case_item.py,sha256=babWakDZfHxWgB1OUwZsPTr8nhDwC-CDBn-vYtgUtUM,2494
39
42
  documente_shared/infrastructure/s3_bucket.py,sha256=vT_yN42RFQXubtUn8ln-j13Os_-25UGClVtXg5Bkv6I,1932
40
43
  documente_shared/infrastructure/sqs_queue.py,sha256=KZWeHZ9zmXmrxoNpOQX7GEdDhZ1knbPXgwSwFwJblGg,1504
41
- documente_shared-0.1.84.dist-info/METADATA,sha256=jukWF48uMxOI5Kdv6KIj0zYlLTpoQw0iHSIlmiiXfSM,881
42
- documente_shared-0.1.84.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
43
- documente_shared-0.1.84.dist-info/RECORD,,
44
+ documente_shared/presentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
+ documente_shared/presentation/presenters.py,sha256=GGAEwefmjCIVepsUA2oZOVLxXbhhiISPM0Jgt6dT6O0,423
46
+ documente_shared-0.1.86.dist-info/METADATA,sha256=iUB2ODiR3m6PjpgmIqt3l2O5yFcyhGelTcNYOQrjqcY,881
47
+ documente_shared-0.1.86.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
48
+ documente_shared-0.1.86.dist-info/RECORD,,