documente_shared 0.1.83__py3-none-any.whl → 0.1.85__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.

@@ -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
@@ -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,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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.83
3
+ Version: 0.1.85
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -20,24 +20,25 @@ documente_shared/domain/entities/processing_case_item.py,sha256=U_g99AJdlRRJpJ0N
20
20
  documente_shared/domain/entities/processing_case_item_filters.py,sha256=-cAQTSWOepMMcGCBg2X3dd0W_8XHuBTlvOB1d-3sVVM,1971
21
21
  documente_shared/domain/entities/processing_event.py,sha256=AMkW4dJjW6ss-uvDeWzVMBIJtax8JNWy-zPo1R-TiWY,1963
22
22
  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
23
+ documente_shared/domain/enums/common.py,sha256=yoq__M53bCCf7B2tbOGdOpieYvGpiJ69s6T0FqvLUII,2687
24
+ documente_shared/domain/enums/document.py,sha256=QwvckW-VJBSujllIVloKlZUh1pI5UnX4oueYbV5CYGw,3205
25
25
  documente_shared/domain/enums/processing_case.py,sha256=LhFhcoWlockxcpplsVdC6M2kpXn7sOdzQySf24wFhx8,1572
26
26
  documente_shared/domain/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  documente_shared/domain/repositories/document.py,sha256=vJzr6c92gqBzyhaEdjrvnoneKRrWmJ0AsvocPnhxiLU,767
28
28
  documente_shared/domain/repositories/processing_case.py,sha256=9jGpnUnXaDgQE1ZKiet7zDVCc7wVvHUrcPOeacebb3s,796
29
29
  documente_shared/domain/repositories/processing_case_item.py,sha256=gPZaQCMYlD6vlnEt6cVIqRmi1K-JWvmDx1f74nd97Cs,974
30
30
  documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
- documente_shared/infrastructure/documente_client.py,sha256=UjVWs9DKa-yhw5DVbcEs8iJxalHOarusVayi_ob6QhE,494
31
+ documente_shared/infrastructure/documente_client.py,sha256=paO66zNelDyA6D6iqTXXFVQ9ERRZoJCGWR3T3hySsaM,503
32
32
  documente_shared/infrastructure/dynamo_table.py,sha256=TMQbcuty7wjDMbuhI8PbT0IGXelgELsNTtqTEQeZ824,2112
33
33
  documente_shared/infrastructure/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  documente_shared/infrastructure/repositories/dynamo_document.py,sha256=_Yp4gtA-n-hJ2w2wAM5BMCs2Mf46Q2Kq3eHqlxudkL4,1443
35
35
  documente_shared/infrastructure/repositories/dynamo_processing_case.py,sha256=IoIHtlaEe4G5TqIV9IvG45a3HRBVHLfNC9sSgQjabUk,1464
36
36
  documente_shared/infrastructure/repositories/dynamo_processing_case_item.py,sha256=4guM8V3YfP7kzYcuVWunGJGmXi0kSSUW8otks39g1vs,1754
37
+ documente_shared/infrastructure/repositories/http_document_processing.py,sha256=7n4lHgpN17CCr4_Dz9WRbsXeb4FDMJZNDUshFipA1B8,2179
37
38
  documente_shared/infrastructure/repositories/http_processing_case.py,sha256=FcOnzPUu-iWjj6O5syzqN61u6xogMoQMfbSnALqeK-c,2258
38
39
  documente_shared/infrastructure/repositories/http_processing_case_item.py,sha256=babWakDZfHxWgB1OUwZsPTr8nhDwC-CDBn-vYtgUtUM,2494
39
40
  documente_shared/infrastructure/s3_bucket.py,sha256=vT_yN42RFQXubtUn8ln-j13Os_-25UGClVtXg5Bkv6I,1932
40
41
  documente_shared/infrastructure/sqs_queue.py,sha256=KZWeHZ9zmXmrxoNpOQX7GEdDhZ1knbPXgwSwFwJblGg,1504
41
- documente_shared-0.1.83.dist-info/METADATA,sha256=KrZ_uLLHahVQVpnb7qrsTL9uuCElcQ2PoiF4OcnBF-M,881
42
- documente_shared-0.1.83.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
43
- documente_shared-0.1.83.dist-info/RECORD,,
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,,