documente_shared 0.1.84__tar.gz → 0.1.86__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.

Potentially problematic release.


This version of documente_shared might be problematic. Click here for more details.

Files changed (48) hide show
  1. {documente_shared-0.1.84 → documente_shared-0.1.86}/PKG-INFO +1 -1
  2. documente_shared-0.1.86/documente_shared/application/dates.py +7 -0
  3. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/enums/common.py +24 -0
  4. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/enums/document.py +53 -0
  5. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/documente_client.py +2 -1
  6. documente_shared-0.1.86/documente_shared/infrastructure/lambdas.py +14 -0
  7. documente_shared-0.1.86/documente_shared/infrastructure/repositories/http_document_processing.py +51 -0
  8. documente_shared-0.1.86/documente_shared/presentation/__init__.py +0 -0
  9. documente_shared-0.1.86/documente_shared/presentation/presenters.py +16 -0
  10. {documente_shared-0.1.84 → documente_shared-0.1.86}/pyproject.toml +1 -1
  11. {documente_shared-0.1.84 → documente_shared-0.1.86}/README.md +0 -0
  12. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/__init__.py +0 -0
  13. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/__init__.py +0 -0
  14. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/digest.py +0 -0
  15. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/exceptions.py +0 -0
  16. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/files.py +0 -0
  17. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/payloads.py +0 -0
  18. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/query_params.py +0 -0
  19. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/time_utils.py +0 -0
  20. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/application/timezone.py +0 -0
  21. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/__init__.py +0 -0
  22. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/base_enum.py +0 -0
  23. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/constants.py +0 -0
  24. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/__init__.py +0 -0
  25. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/document.py +0 -0
  26. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/document_metadata.py +0 -0
  27. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/in_memory_result.py +0 -0
  28. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/processing_case.py +0 -0
  29. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/processing_case_filters.py +0 -0
  30. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/processing_case_item.py +0 -0
  31. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/processing_case_item_filters.py +0 -0
  32. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/entities/processing_event.py +0 -0
  33. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/enums/__init__.py +0 -0
  34. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/enums/processing_case.py +0 -0
  35. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/repositories/__init__.py +0 -0
  36. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/repositories/document.py +0 -0
  37. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/repositories/processing_case.py +0 -0
  38. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/domain/repositories/processing_case_item.py +0 -0
  39. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/__init__.py +0 -0
  40. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/dynamo_table.py +0 -0
  41. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/__init__.py +0 -0
  42. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/dynamo_document.py +0 -0
  43. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/dynamo_processing_case.py +0 -0
  44. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/dynamo_processing_case_item.py +0 -0
  45. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/http_processing_case.py +0 -0
  46. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/repositories/http_processing_case_item.py +0 -0
  47. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/s3_bucket.py +0 -0
  48. {documente_shared-0.1.84 → documente_shared-0.1.86}/documente_shared/infrastructure/sqs_queue.py +0 -0
@@ -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
@@ -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
+
@@ -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
  [tool.poetry]
2
2
  name = "documente_shared"
3
- version = "0.1.84"
3
+ version = "0.1.86"
4
4
  description = "Shared utilities for Documente AI projects"
5
5
  authors = ["Tech <tech@llamitai.com>"]
6
6
  license = "MIT"