sharedkernel 1.6.10__tar.gz → 1.7.0__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.
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/PKG-INFO +4 -1
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/README.md +2 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/setup.py +3 -2
- sharedkernel-1.7.0/sharedkernel/s3_uploader.py +77 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel.egg-info/PKG-INFO +4 -1
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel.egg-info/SOURCES.txt +1 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel.egg-info/requires.txt +1 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/setup.cfg +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/common.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/mongo_generic_repository.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/vector_database_repository/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/vector_database_repository/chroma_startegy.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/vector_database_repository/vector_database_repository.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/vector_database_repository/vector_database_strategy.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/date_converter.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/enum/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/enum/error_code.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/enum/vector_database_type.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/normalizer/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/objects/base_document.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/objects/result.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-1.6.10 → sharedkernel-1.7.0}/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.
|
|
3
|
+
Version: 1.7.0
|
|
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,14 @@ 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.0
|
|
24
|
+
- Implement S3 Uploader
|
|
22
25
|
### Version 1.6.10
|
|
23
26
|
- Add updated_on to BaseDocument
|
|
24
27
|
- 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.
|
|
38
|
+
version="1.7.0",
|
|
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,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.
|
|
3
|
+
Version: 1.7.0
|
|
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,14 @@ 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.0
|
|
24
|
+
- Implement S3 Uploader
|
|
22
25
|
### Version 1.6.10
|
|
23
26
|
- Add updated_on to BaseDocument
|
|
24
27
|
- Update phonenumber normalizer
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/database/mongo_generic_repository.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-1.6.10 → sharedkernel-1.7.0}/sharedkernel/normalizer/phone_number_normalizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|