documente_shared 0.1.72b0__tar.gz → 0.1.74__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 (44) hide show
  1. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/PKG-INFO +1 -1
  2. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/README.md +16 -16
  3. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/__init__.py +0 -0
  4. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/__init__.py +0 -0
  5. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/digest.py +7 -7
  6. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/exceptions.py +23 -23
  7. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/files.py +22 -22
  8. documente_shared-0.1.74/documente_shared/application/query_params.py +129 -0
  9. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/time_utils.py +13 -13
  10. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/application/timezone.py +7 -7
  11. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/__init__.py +0 -0
  12. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/base_enum.py +53 -53
  13. documente_shared-0.1.74/documente_shared/domain/constants.py +8 -0
  14. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/__init__.py +0 -0
  15. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/document.py +348 -348
  16. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/document_metadata.py +63 -63
  17. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/in_memory_result.py +51 -51
  18. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/processing_case.py +145 -144
  19. documente_shared-0.1.74/documente_shared/domain/entities/processing_case_filters.py +48 -0
  20. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/processing_case_item.py +216 -216
  21. documente_shared-0.1.74/documente_shared/domain/entities/processing_case_item_filters.py +51 -0
  22. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/entities/processing_event.py +49 -49
  23. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/enums/__init__.py +0 -0
  24. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/enums/common.py +95 -95
  25. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/enums/document.py +71 -71
  26. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/enums/processing_case.py +55 -54
  27. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/repositories/__init__.py +0 -0
  28. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/repositories/document.py +24 -24
  29. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/repositories/processing_case.py +24 -24
  30. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/domain/repositories/processing_case_item.py +25 -29
  31. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/__init__.py +0 -0
  32. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/documente_client.py +20 -20
  33. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/dynamo_table.py +75 -75
  34. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/__init__.py +0 -0
  35. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/dynamo_document.py +43 -43
  36. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/dynamo_processing_case.py +43 -43
  37. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/dynamo_processing_case_item.py +43 -54
  38. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/http_processing_case.py +41 -40
  39. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/repositories/http_processing_case_item.py +43 -53
  40. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/s3_bucket.py +57 -57
  41. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/documente_shared/infrastructure/sqs_queue.py +47 -47
  42. {documente_shared-0.1.72b0 → documente_shared-0.1.74}/pyproject.toml +40 -40
  43. documente_shared-0.1.72b0/documente_shared/domain/constants.py +0 -3
  44. documente_shared-0.1.72b0/documente_shared/infrastructure/repositories/http_document_processing.py +0 -41
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.72b0
3
+ Version: 0.1.74
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -1,17 +1,17 @@
1
-
2
- # Documente Shared
3
-
4
- Utilidades para proyectos Documente AI
5
-
6
- ## Instalación
7
-
8
- ```bash
9
- make build
10
- ```
11
-
12
- ## Publicación
13
- Publica `documente-shared` en PyPi
14
-
15
- ```bash
16
- make publish
1
+
2
+ # Documente Shared
3
+
4
+ Utilidades para proyectos Documente AI
5
+
6
+ ## Instalación
7
+
8
+ ```bash
9
+ make build
10
+ ```
11
+
12
+ ## Publicación
13
+ Publica `documente-shared` en PyPi
14
+
15
+ ```bash
16
+ make publish
17
17
  ```
@@ -1,7 +1,7 @@
1
- import hashlib
2
-
3
-
4
- def get_file_digest(file_bytes: bytes) -> str:
5
- sha256_hash = hashlib.sha256()
6
- sha256_hash.update(file_bytes)
7
- return sha256_hash.hexdigest()
1
+ import hashlib
2
+
3
+
4
+ def get_file_digest(file_bytes: bytes) -> str:
5
+ sha256_hash = hashlib.sha256()
6
+ sha256_hash.update(file_bytes)
7
+ return sha256_hash.hexdigest()
@@ -1,23 +1,23 @@
1
- import sentry_sdk
2
- from functools import wraps
3
- from typing import Callable, Any, TypeVar
4
-
5
- F = TypeVar("F", bound=Callable[..., Any])
6
-
7
- def initialize_sentry(dsn: str, environment: str = 'dev') -> None:
8
- if not sentry_sdk.Hub.current.client:
9
- sentry_sdk.init(
10
- dsn=dsn,
11
- environment=environment,
12
- )
13
-
14
- def track_exceptions(func: F) -> F:
15
- @wraps(func)
16
- def wrapper(*args: Any, **kwargs: Any) -> Any:
17
- try:
18
- return func(*args, **kwargs)
19
- except Exception as e:
20
- sentry_sdk.capture_exception(e)
21
- sentry_sdk.flush()
22
- raise
23
- return wrapper # type: ignore
1
+ import sentry_sdk
2
+ from functools import wraps
3
+ from typing import Callable, Any, TypeVar
4
+
5
+ F = TypeVar("F", bound=Callable[..., Any])
6
+
7
+ def initialize_sentry(dsn: str, environment: str = 'dev') -> None:
8
+ if not sentry_sdk.Hub.current.client:
9
+ sentry_sdk.init(
10
+ dsn=dsn,
11
+ environment=environment,
12
+ )
13
+
14
+ def track_exceptions(func: F) -> F:
15
+ @wraps(func)
16
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
17
+ try:
18
+ return func(*args, **kwargs)
19
+ except Exception as e:
20
+ sentry_sdk.capture_exception(e)
21
+ sentry_sdk.flush()
22
+ raise
23
+ return wrapper # type: ignore
@@ -1,22 +1,22 @@
1
- from os import path
2
- from typing import Tuple, Optional
3
-
4
-
5
- def split_file_params(filepath: str) -> Tuple[str, str, str]:
6
- folder_path = path.dirname(filepath)
7
- filename = path.splitext(path.basename(filepath))[0]
8
- extension = path.splitext(filepath)[1]
9
- extension = extension.replace('.', '')
10
- return folder_path, filename, extension
11
-
12
-
13
- def get_filename_from_path(file_path: Optional[str]) -> Optional[str]:
14
- if not file_path:
15
- return None
16
- return path.basename(file_path)
17
-
18
-
19
- def remove_slash_from_path(file_path: str) -> str:
20
- if file_path and file_path.startswith('/'):
21
- return file_path[1:]
22
- return file_path
1
+ from os import path
2
+ from typing import Tuple, Optional
3
+
4
+
5
+ def split_file_params(filepath: str) -> Tuple[str, str, str]:
6
+ folder_path = path.dirname(filepath)
7
+ filename = path.splitext(path.basename(filepath))[0]
8
+ extension = path.splitext(filepath)[1]
9
+ extension = extension.replace('.', '')
10
+ return folder_path, filename, extension
11
+
12
+
13
+ def get_filename_from_path(file_path: Optional[str]) -> Optional[str]:
14
+ if not file_path:
15
+ return None
16
+ return path.basename(file_path)
17
+
18
+
19
+ def remove_slash_from_path(file_path: str) -> str:
20
+ if file_path and file_path.startswith('/'):
21
+ return file_path[1:]
22
+ return file_path
@@ -0,0 +1,129 @@
1
+ from documente_shared.domain.base_enum import BaseEnum
2
+
3
+ from dataclasses import dataclass
4
+ from datetime import datetime
5
+ from typing import List, Optional, Type, Union
6
+ from uuid import UUID
7
+
8
+
9
+
10
+ def camelize_string(value: str) -> str:
11
+ if not value:
12
+ return value
13
+ value = "".join(word.title() for word in value.split("_"))
14
+ return value[:1].lower() + value[1:]
15
+
16
+
17
+ @dataclass
18
+ class QueryParams(object):
19
+ params: Union[dict]
20
+
21
+ def get(self, key, default=None):
22
+ return self.params.get(key, default) or self.params.get(camelize_string(key), default)
23
+
24
+ def get_datetime(self, key: str, default=None):
25
+ try:
26
+ value = self.get_str(key, default)
27
+ if not value:
28
+ return None
29
+ return datetime.strptime(value, "%Y-%m-%d")
30
+ except (ValueError, TypeError):
31
+ return None
32
+
33
+ def get_str(self, key, default=None):
34
+ try:
35
+ return self._get_or_none(key, str, default)
36
+ except (ValueError, TypeError):
37
+ return None
38
+
39
+ def get_int(self, key, default=None):
40
+ try:
41
+ return self._get_or_none(key, int, default)
42
+ except (ValueError, TypeError):
43
+ return None
44
+
45
+ def get_float(self, key, default=None):
46
+ try:
47
+ return self._get_or_none(key, float, default)
48
+ except (ValueError, TypeError):
49
+ return None
50
+
51
+ def get_bool(self, key, default=False):
52
+ try:
53
+ value = self.get(key, default)
54
+ if isinstance(value, bool):
55
+ return value
56
+ elif isinstance(value, str):
57
+ return value in ["true", "True", "TRUE", "1", "active"]
58
+ elif value is None:
59
+ return None
60
+ return False
61
+ except (ValueError, TypeError):
62
+ return None
63
+
64
+ def get_uuid(self, key, default=None):
65
+ try:
66
+ return self._get_or_none(key, UUID, default)
67
+ except (ValueError, TypeError):
68
+ return None
69
+
70
+ def get_uuid_list(self, key, default=None):
71
+ def parse_str(value):
72
+ uuid_list = []
73
+ for uuid_str in value.split(","):
74
+ try:
75
+ uuid_list.append(UUID(uuid_str))
76
+ except ValueError:
77
+ pass
78
+ return uuid_list
79
+
80
+ try:
81
+ return self._get_or_none(key, parse_str, default)
82
+ except (ValueError, TypeError):
83
+ return None
84
+
85
+ def get_list(self, key, default=None):
86
+ default = default or []
87
+ try:
88
+ return self.params.getlist(key) or self.params.getlist(camelize_string(key)) or default
89
+ except (ValueError, TypeError):
90
+ return None
91
+
92
+ def get_enum(
93
+ self,
94
+ key: str,
95
+ enum_class: Type[BaseEnum],
96
+ default: BaseEnum = None,
97
+ ) -> Optional[BaseEnum]:
98
+ try:
99
+ str_value = self.get_str(key) or default
100
+ return enum_class.from_value(str_value) if str_value else None
101
+ except (ValueError, TypeError):
102
+ return None
103
+
104
+ def get_enum_list(
105
+ self,
106
+ key: str,
107
+ enum_class: Type[BaseEnum],
108
+ default: BaseEnum = None,
109
+ ) -> List:
110
+ str_value = self.get_str(key) or default
111
+ if not str_value:
112
+ return []
113
+ converted_enum_list = []
114
+ str_enum_items = str_value.split(",")
115
+ for str_enum_item in str_enum_items:
116
+ enum_value = enum_class.from_value(value=str_enum_item)
117
+ if not enum_value:
118
+ continue
119
+ converted_enum_list.append(enum_value)
120
+ return converted_enum_list
121
+
122
+ def _get_or_none(
123
+ self,
124
+ key: str,
125
+ cast_type: Type[Union[str, int, float, bool, UUID]],
126
+ default=None,
127
+ ) -> Optional[Union[str, int, float, bool, UUID]]:
128
+ item_value = self.get(key, default)
129
+ return cast_type(item_value) if item_value else default
@@ -1,13 +1,13 @@
1
- from datetime import datetime
2
- from typing import Union, Optional
3
-
4
-
5
- def get_datetime_from_data(input_datetime: Union[datetime, str]) -> Optional[datetime]:
6
- if isinstance(input_datetime, datetime):
7
- return input_datetime
8
- elif isinstance(input_datetime, str) and bool(input_datetime):
9
- try:
10
- return datetime.fromisoformat(input_datetime)
11
- except ValueError:
12
- return None
13
- return None
1
+ from datetime import datetime
2
+ from typing import Union, Optional
3
+
4
+
5
+ def get_datetime_from_data(input_datetime: Union[datetime, str]) -> Optional[datetime]:
6
+ if isinstance(input_datetime, datetime):
7
+ return input_datetime
8
+ elif isinstance(input_datetime, str) and bool(input_datetime):
9
+ try:
10
+ return datetime.fromisoformat(input_datetime)
11
+ except ValueError:
12
+ return None
13
+ return None
@@ -1,7 +1,7 @@
1
- from datetime import datetime, timezone
2
-
3
-
4
- def ensure_timezone(dt: datetime, tz=timezone.utc) -> datetime:
5
- if dt.tzinfo is None:
6
- return dt.replace(tzinfo=tz)
7
- return dt
1
+ from datetime import datetime, timezone
2
+
3
+
4
+ def ensure_timezone(dt: datetime, tz=timezone.utc) -> datetime:
5
+ if dt.tzinfo is None:
6
+ return dt.replace(tzinfo=tz)
7
+ return dt
@@ -1,54 +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
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
54
  return None
@@ -0,0 +1,8 @@
1
+ import pytz
2
+ from os import environ
3
+
4
+
5
+ la_paz_tz = pytz.timezone("America/La_Paz")
6
+
7
+ DOCUMENTE_API_URL = environ.get("DOCUMENTE_API_URL")
8
+ DOCUMENTE_API_KEY = environ.get("DOCUMENTE_API_KEY")