sharedkernel 1.6.10__tar.gz → 1.7.1__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.
Files changed (34) hide show
  1. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/PKG-INFO +6 -1
  2. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/README.md +4 -0
  3. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/setup.py +3 -2
  4. sharedkernel-1.7.1/sharedkernel/objects/base_document.py +10 -0
  5. sharedkernel-1.7.1/sharedkernel/s3_uploader.py +77 -0
  6. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel.egg-info/PKG-INFO +6 -1
  7. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel.egg-info/SOURCES.txt +1 -0
  8. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel.egg-info/requires.txt +1 -0
  9. sharedkernel-1.6.10/sharedkernel/objects/base_document.py +0 -10
  10. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/setup.cfg +0 -0
  11. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/common.py +0 -0
  12. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/__init__.py +0 -0
  13. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/mongo_generic_repository.py +0 -0
  14. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/vector_database_repository/__init__.py +0 -0
  15. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/vector_database_repository/chroma_startegy.py +0 -0
  16. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/vector_database_repository/vector_database_repository.py +0 -0
  17. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/database/vector_database_repository/vector_database_strategy.py +0 -0
  18. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/date_converter.py +0 -0
  19. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/enum/__init__.py +0 -0
  20. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/enum/error_code.py +0 -0
  21. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/enum/vector_database_type.py +0 -0
  22. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/exception/__init__.py +0 -0
  23. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/exception/exception.py +0 -0
  24. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/exception/exception_handlers.py +0 -0
  25. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/jwt_service.py +0 -0
  26. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/normalizer/__init__.py +0 -0
  27. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
  28. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/objects/__init__.py +0 -0
  29. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/objects/jwt_model.py +0 -0
  30. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/objects/result.py +0 -0
  31. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/regex_masking.py +0 -0
  32. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel/string_extentions.py +0 -0
  33. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel.egg-info/dependency_links.txt +0 -0
  34. {sharedkernel-1.6.10 → sharedkernel-1.7.1}/sharedkernel.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sharedkernel
3
- Version: 1.6.10
3
+ Version: 1.7.1
4
4
  Summary: sharekernel is a shared package between all python projects
5
5
  Author: Smilinno
6
6
  Description-Content-Type: text/markdown
@@ -14,11 +14,16 @@ Requires-Dist: persian_tools
14
14
  Requires-Dist: sentry-sdk
15
15
  Requires-Dist: jdatetime
16
16
  Requires-Dist: persiantools
17
+ Requires-Dist: boto3
17
18
 
18
19
  # SharedKernel
19
20
  this a shared kernel package
20
21
 
21
22
  # Change Log
23
+ ### Version 1.7.1
24
+ - Update BaseDocument initial values
25
+ ### Version 1.7.0
26
+ - Implement S3 Uploader
22
27
  ### Version 1.6.10
23
28
  - Add updated_on to BaseDocument
24
29
  - Update phonenumber normalizer
@@ -2,6 +2,10 @@
2
2
  this a shared kernel package
3
3
 
4
4
  # Change Log
5
+ ### Version 1.7.1
6
+ - Update BaseDocument initial values
7
+ ### Version 1.7.0
8
+ - Implement S3 Uploader
5
9
  ### Version 1.6.10
6
10
  - Add updated_on to BaseDocument
7
11
  - Update phonenumber normalizer
@@ -31,10 +31,11 @@ setup(
31
31
  "persian_tools",
32
32
  "sentry-sdk",
33
33
  "jdatetime",
34
- "persiantools"
34
+ "persiantools",
35
+ "boto3"
35
36
  ],
36
37
  # *strongly* suggested for sharing
37
- version="1.6.10",
38
+ version="1.7.1",
38
39
  description="sharekernel is a shared package between all python projects",
39
40
  long_description=long_description,
40
41
  long_description_content_type="text/markdown",
@@ -0,0 +1,10 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import Optional
3
+ from datetime import datetime
4
+
5
+
6
+ class BaseDocument(BaseModel):
7
+ id: Optional[str]
8
+ is_deleted: bool = False
9
+ created_on: datetime = Field(default_factory=datetime.now)
10
+ updated_on: datetime = Field(default_factory=datetime.now)
@@ -0,0 +1,77 @@
1
+ import requests
2
+ import boto3
3
+ from io import BytesIO
4
+ import uuid
5
+ import os
6
+
7
+ class S3Uploader:
8
+ def __init__(self, endpoint_url, bucket, access_key, secret_key):
9
+ """
10
+ Initializes the S3Uploader with credentials and optional endpoint/region.
11
+
12
+ :param endpoint_url: Custom endpoint URL (for S3-compatible services like MinIO)
13
+ :param bucket: Name of S3 bucket
14
+ :param access_key: Access key
15
+ :param secret_key: Secret key
16
+ """
17
+ self.endpoint_url = endpoint_url
18
+ self.bucket = bucket
19
+ self.access_key = access_key
20
+ self.secret_key = secret_key
21
+
22
+ # Initialize the S3 client
23
+ self.s3 = boto3.client(
24
+ 's3',
25
+ endpoint_url=self.endpoint_url,
26
+ aws_access_key_id=self.access_key,
27
+ aws_secret_access_key=self.secret_key,
28
+ )
29
+
30
+ def upload_file_object(self, file_obj, object_name=None, file_extension=None):
31
+ """
32
+ Uploads a file object to an S3 bucket and returns its URL.
33
+
34
+ :param file_obj: File object to upload
35
+ :param object_name: S3 file name to save as (optional)
36
+ :param file_extension: File extension to append to object name (optional)
37
+ :return: URL of the uploaded file if successful, else False
38
+ """
39
+ # Use uuid4 to generate a unique object_name if not provided
40
+ if object_name is None:
41
+ object_name = str(uuid.uuid4())
42
+
43
+ # Append the file extension to the object_name
44
+ if file_extension:
45
+ object_name += file_extension
46
+
47
+ # Upload the file object
48
+ self.s3.upload_fileobj(file_obj, self.bucket, object_name, ExtraArgs={'ACL':'public-read'})
49
+ print(f"File object uploaded to {self.bucket} as {object_name}.")
50
+
51
+ # Construct the URL of the uploaded file
52
+ file_url = f"{self.endpoint_url}/{self.bucket}/{object_name}"
53
+
54
+ return file_url
55
+
56
+ def upload_file_from_url(self, file_url, object_name=None):
57
+ """
58
+ Downloads a file from a URL and uploads it to an S3 bucket, returning its URL.
59
+
60
+ :param file_url: URL of the file to download
61
+ :param object_name: S3 file name to save as (optional)
62
+ :return: URL of the uploaded file if successful, else False
63
+ """
64
+ # Step 1: Download the file from the provided URL
65
+ response = requests.get(file_url)
66
+ response.raise_for_status() # Check if the request was successful
67
+
68
+ # Extract file extension from the URL if available
69
+ file_extension = os.path.splitext(file_url)[1] # Get extension from URL (e.g., .jpg, .png, etc.)
70
+
71
+ # Use the filename from the URL if no object_name is provided, otherwise use uuid4
72
+ if object_name is None:
73
+ object_name = str(uuid.uuid4()) # Default to UUID if filename can't be extracted
74
+
75
+ # Step 2: Upload the file to S3
76
+ file_obj = BytesIO(response.content)
77
+ return self.upload_file_object(file_obj, object_name, file_extension)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sharedkernel
3
- Version: 1.6.10
3
+ Version: 1.7.1
4
4
  Summary: sharekernel is a shared package between all python projects
5
5
  Author: Smilinno
6
6
  Description-Content-Type: text/markdown
@@ -14,11 +14,16 @@ Requires-Dist: persian_tools
14
14
  Requires-Dist: sentry-sdk
15
15
  Requires-Dist: jdatetime
16
16
  Requires-Dist: persiantools
17
+ Requires-Dist: boto3
17
18
 
18
19
  # SharedKernel
19
20
  this a shared kernel package
20
21
 
21
22
  # Change Log
23
+ ### Version 1.7.1
24
+ - Update BaseDocument initial values
25
+ ### Version 1.7.0
26
+ - Implement S3 Uploader
22
27
  ### Version 1.6.10
23
28
  - Add updated_on to BaseDocument
24
29
  - Update phonenumber normalizer
@@ -4,6 +4,7 @@ sharedkernel/common.py
4
4
  sharedkernel/date_converter.py
5
5
  sharedkernel/jwt_service.py
6
6
  sharedkernel/regex_masking.py
7
+ sharedkernel/s3_uploader.py
7
8
  sharedkernel/string_extentions.py
8
9
  sharedkernel.egg-info/PKG-INFO
9
10
  sharedkernel.egg-info/SOURCES.txt
@@ -8,3 +8,4 @@ persian_tools
8
8
  sentry-sdk
9
9
  jdatetime
10
10
  persiantools
11
+ boto3
@@ -1,10 +0,0 @@
1
- from pydantic import BaseModel
2
- from typing import Optional
3
- from datetime import datetime
4
-
5
-
6
- class BaseDocument(BaseModel):
7
- id: Optional[str]
8
- is_deleted: bool = False
9
- created_on: datetime = datetime.now()
10
- updated_on: datetime = datetime.now()
File without changes