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

File without changes
@@ -0,0 +1,54 @@
1
+ from enum import Enum
2
+ from typing import Union, Optional
3
+
4
+
5
+ class BaseEnum(Enum):
6
+ """Provides the common functionalties to multiple model choices."""
7
+
8
+ @classmethod
9
+ def get_members(cls):
10
+ return [tag for tag in cls if type(tag.value) in [int, str, float]]
11
+
12
+ @classmethod
13
+ def choices(cls):
14
+ """Generate choice options for models."""
15
+ return [
16
+ (option.value, option.value)
17
+ for option in cls
18
+ if type(option.value) in [int, str, float]
19
+ ]
20
+
21
+ @classmethod
22
+ def values(cls):
23
+ """Returns values from choices."""
24
+ return [option.value for option in cls]
25
+
26
+ def __str__(self): # noqa: D105
27
+ return str(self.value)
28
+
29
+ def __repr__(self):
30
+ return self.__str__()
31
+
32
+ def __hash__(self):
33
+ return hash(self.value)
34
+
35
+ @classmethod
36
+ def as_list(cls):
37
+ """Returns properties as a list."""
38
+ return [
39
+ value
40
+ for key, value in cls.__dict__.items()
41
+ if isinstance(value, str) and not key.startswith('__')
42
+ ]
43
+
44
+ @classmethod
45
+ def from_value(
46
+ cls,
47
+ value: Union[str, int],
48
+ ) -> Optional['BaseEnum']:
49
+ for tag in cls:
50
+ if isinstance(tag.value, str) and str(tag.value).upper() == str(value).upper():
51
+ return tag
52
+ elif not isinstance(tag.value, str) and tag.value == value:
53
+ return tag
54
+ return None
@@ -0,0 +1,110 @@
1
+ from dataclasses import dataclass
2
+ from datetime import datetime
3
+ from typing import Optional
4
+
5
+ from documente_shared.domain.enums import DocumentProcessStatus
6
+
7
+
8
+ @dataclass
9
+ class DocumentProcess(object):
10
+ digest: str
11
+ status: DocumentProcessStatus
12
+ file_path: str
13
+ processed_csv_path: str
14
+ processed_xlsx_path: str
15
+ processing_time: Optional[float] = None
16
+ enqueued_at: Optional[datetime] = None
17
+ started_at: Optional[datetime] = None
18
+ failed_at: Optional[datetime] = None
19
+ processed_at: Optional[datetime] = None
20
+
21
+ @property
22
+ def is_pending(self) -> bool:
23
+ return self.status == DocumentProcessStatus.PENDING
24
+
25
+ @property
26
+ def is_enqueued(self) -> bool:
27
+ return self.status == DocumentProcessStatus.ENQUEUED
28
+
29
+ @property
30
+ def is_processing(self) -> bool:
31
+ return self.status == DocumentProcessStatus.PROCESSING
32
+
33
+ @property
34
+ def is_completed(self) -> bool:
35
+ return self.status == DocumentProcessStatus.COMPLETED
36
+
37
+ @property
38
+ def is_failed(self) -> bool:
39
+ return self.status == DocumentProcessStatus.FAILED
40
+
41
+ @property
42
+ def is_valid(self) -> bool:
43
+ return all([
44
+ self.digest,
45
+ self.status,
46
+ self.file_path,
47
+ ])
48
+
49
+ def enqueue(self):
50
+ self.status = DocumentProcessStatus.ENQUEUED
51
+ self.enqueued_at = datetime.now()
52
+
53
+ def processing(self):
54
+ self.status = DocumentProcessStatus.PROCESSING
55
+ self.started_at = datetime.now()
56
+
57
+ def failed(self):
58
+ self.status = DocumentProcessStatus.FAILED
59
+ self.failed_at = datetime.now()
60
+
61
+ def completed(self):
62
+ self.status = DocumentProcessStatus.COMPLETED
63
+ self.processed_at = datetime.now()
64
+
65
+
66
+
67
+ @property
68
+ def to_dict(self) -> dict:
69
+ return {
70
+ 'digest': self.digest,
71
+ 'status': self.status.value,
72
+ 'file_path': self.file_path,
73
+ 'processed_csv_path': self.processed_csv_path,
74
+ 'processed_xlsx_path': self.processed_xlsx_path,
75
+ 'processing_time': self.processing_time,
76
+ 'enqueued_at': self.enqueued_at.isoformat() if self.enqueued_at else None,
77
+ 'started_at': self.started_at.isoformat() if self.started_at else None,
78
+ 'failed_at': self.failed_at.isoformat() if self.failed_at else None,
79
+ 'processed_at': self.processed_at.isoformat() if self.processed_at else None,
80
+ }
81
+
82
+ @classmethod
83
+ def from_dict(cls, data: dict) -> 'DocumentProcess':
84
+ return cls(
85
+ digest=data.get('digest'),
86
+ status=DocumentProcessStatus.from_value(data.get('status')),
87
+ file_path=data.get('file_path'),
88
+ processed_csv_path=data.get('processed_csv_path'),
89
+ processed_xlsx_path=data.get('processed_xlsx_path'),
90
+ processing_time=(
91
+ data.get('processing_time')
92
+ if data.get('processing_time') else None
93
+ ),
94
+ enqueued_at=(
95
+ datetime.fromisoformat(data.get('enqueued_at'))
96
+ if data.get('enqueued_at') else None
97
+ ),
98
+ started_at=(
99
+ datetime.fromisoformat(data.get('started_at'))
100
+ if data.get('started_at') else None
101
+ ),
102
+ failed_at=(
103
+ datetime.fromisoformat(data.get('failed_at'))
104
+ if data.get('failed_at') else None
105
+ ),
106
+ processed_at=(
107
+ datetime.fromisoformat(data.get('processed_at'))
108
+ if data.get('processed_at') else None
109
+ ),
110
+ )
@@ -1,4 +1,4 @@
1
- from domain.base_enum import BaseEnum
1
+ from documente_shared.domain.base_enum import BaseEnum
2
2
 
3
3
 
4
4
  class DocumentProcessStatus(BaseEnum):
@@ -0,0 +1,14 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from documente_shared.domain.entities import DocumentProcess
4
+
5
+
6
+ class DocumentProcessRepository(ABC):
7
+
8
+ @abstractmethod
9
+ def persist(self, instance: DocumentProcess) -> DocumentProcess:
10
+ raise NotImplementedError
11
+
12
+ @abstractmethod
13
+ def delete(self, instance: DocumentProcess):
14
+ raise NotImplementedError
File without changes
@@ -0,0 +1,10 @@
1
+ from documente_shared.domain.entities import DocumentProcess
2
+ from documente_shared.domain.repositories import DocumentProcessRepository
3
+
4
+
5
+ class DynamoDocumentProcessRepository(DocumentProcessRepository):
6
+ def persist(self, instance: DocumentProcess) -> DocumentProcess:
7
+ pass
8
+
9
+ def delete(self, instance: DocumentProcess):
10
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -13,3 +13,10 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: boto3 (>=1.34.102,<2.0.0)
15
15
  Requires-Dist: botocore (>=1.34.102,<2.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+
19
+ # Documente Shared
20
+
21
+ Utilidades para proyectos Documente AI
22
+
@@ -0,0 +1,11 @@
1
+ documente_shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ documente_shared/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ documente_shared/domain/base_enum.py,sha256=DojAfn-zQdtjtImeHUpBzE6TBTm07XrbMOdW3h8RVd8,1449
4
+ documente_shared/domain/entities.py,sha256=A9fepr2Y5IkCxe8W18uhos4UlEJ8VGSTd8PSCcEY98M,3600
5
+ documente_shared/domain/enums.py,sha256=LF-gY3EyucQSmGBxXNy8z4Cb4Ry672muPtz5Xt7e9oo,227
6
+ documente_shared/domain/repositories.py,sha256=j9BtQOJiNiXJ6nVo7MnP1oBuoN02Ox9cyCrvPGlkD30,365
7
+ documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ documente_shared/infrastructure/dynamo_repositories.py,sha256=-lyG9oaskt6LdgdETFMZTUPS0_3fooLJzauX1pNDaos,348
9
+ documente_shared-0.1.2.dist-info/METADATA,sha256=4QFYDMlB9U5b83e6R6law8lRf_Dy_lc3nrpriOrZFAs,639
10
+ documente_shared-0.1.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
11
+ documente_shared-0.1.2.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- documente_shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- documente_shared/enums.py,sha256=CABjh0FRrBjoD2Q2-CwxTupnVclXi-YWYfurjnbg1kQ,210
3
- documente_shared-0.1.0.dist-info/METADATA,sha256=oc1xunRhkRXVERHmITA2mXrdbFRbX2Sal6B_2Ffjbi4,537
4
- documente_shared-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
5
- documente_shared-0.1.0.dist-info/RECORD,,