cloudtoolbox 0.1.0__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.
cloud/__init__.py ADDED
File without changes
File without changes
cloud/amazon/s3.py ADDED
@@ -0,0 +1,11 @@
1
+ from typing import Any
2
+
3
+ import boto3
4
+
5
+
6
+ class Uploader:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = boto3.client("s3", *args, **kwargs)
9
+
10
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None:
11
+ self.client.upload_file(source_filename, bucket_name, destination_filename)
cloud/factory.py ADDED
@@ -0,0 +1,29 @@
1
+ from typing import Any, Callable, Type
2
+
3
+ from cloud.protocols import MessagePublisher, StorageUploader
4
+
5
+ error_message = "%(class)s does not implement %(protocol)s protocol"
6
+
7
+
8
+ def storage_uploader(
9
+ uploader_class: Type[StorageUploader], *args: Any, **kwargs: Any
10
+ ) -> Callable[[], StorageUploader]:
11
+ error = error_message % {"class": uploader_class.__name__, "protocol": "StorageUploader"}
12
+ assert issubclass(uploader_class, StorageUploader), error
13
+
14
+ def maker() -> StorageUploader:
15
+ return uploader_class(*args, **kwargs)
16
+
17
+ return maker
18
+
19
+
20
+ def message_publisher(
21
+ publisher_class: Type[MessagePublisher], *args: Any, **kwargs: Any
22
+ ) -> Callable[[], MessagePublisher]:
23
+ error = error_message % {"class": publisher_class.__name__, "protocol": "MessagePublisher"}
24
+ assert issubclass(publisher_class, MessagePublisher), error
25
+
26
+ def maker() -> MessagePublisher:
27
+ return publisher_class(*args, **kwargs)
28
+
29
+ return maker
File without changes
cloud/google/pubsub.py ADDED
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+ from google.cloud import pubsub_v1
4
+
5
+
6
+ class Publisher:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = pubsub_v1.PublisherClient(*args, **kwargs)
9
+
10
+ def publish(self, recipient: str, message: str, **attrs: Any) -> None:
11
+ future = self.client.publish(recipient, data=message.encode(), **attrs)
12
+ future.result()
@@ -0,0 +1,13 @@
1
+ from typing import Any
2
+
3
+ from google.cloud import storage
4
+
5
+
6
+ class Uploader:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = storage.Client(*args, **kwargs)
9
+
10
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None:
11
+ bucket = self.client.bucket(bucket_name)
12
+ blob = bucket.blob(destination_filename)
13
+ blob.upload_from_filename(source_filename)
cloud/protocols.py ADDED
@@ -0,0 +1,11 @@
1
+ from typing import Any, Protocol, runtime_checkable
2
+
3
+
4
+ @runtime_checkable
5
+ class StorageUploader(Protocol):
6
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None: ...
7
+
8
+
9
+ @runtime_checkable
10
+ class MessagePublisher(Protocol):
11
+ def publish(self, recipient: str, message: str, **attrs: Any) -> None: ...
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Noverde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: cloudtoolbox
3
+ Version: 0.1.0
4
+ Summary: Toolbox for the cloud.
5
+ Author-email: Dotz Developers <devs-dotz@dotz.com>
6
+ Keywords: cloud,tools,utilities,google,gcp,amazon,aws
7
+ Classifier: Programming Language :: Python :: 3
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Provides-Extra: amazon
12
+ Requires-Dist: boto3 ; extra == 'amazon'
13
+ Provides-Extra: google
14
+ Requires-Dist: google-cloud-pubsub ; extra == 'google'
15
+ Requires-Dist: google-cloud-storage ; extra == 'google'
16
+
17
+ # Cloud Toolbox
18
+
19
+ Decouple your applications from cloud providers with carefully crafted service interfaces.
@@ -0,0 +1,13 @@
1
+ cloud/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cloud/factory.py,sha256=EG32yXMi3gwiXD3LwvVKyQ1oAuCb8fufMIU14y83uhI,956
3
+ cloud/protocols.py,sha256=t7QtDuZByNJ644D1BwUYe_G20GQiZ-ljMwvdT4HqXTI,341
4
+ cloud/amazon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ cloud/amazon/s3.py,sha256=zeCaOnjRNWe0QoB1UVF81NbMAGo5uqe69yFSWjKZSY4,354
6
+ cloud/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ cloud/google/pubsub.py,sha256=WoZHevtzVHjqW1fC4FQ0qVWF2slfoI7iv-2OD1ANxFQ,382
8
+ cloud/google/storage.py,sha256=ESGYX5gBNeoBQWNTsJgA7s5u1GsL3koU4VFCgGUDcYw,435
9
+ cloudtoolbox-0.1.0.dist-info/LICENSE,sha256=zGjU5vOKeg11lCvxB5w228mJfwK6LYirQYLGOWBIvL8,1064
10
+ cloudtoolbox-0.1.0.dist-info/METADATA,sha256=9SYxDDhfW8pQYMnOirQM4CJZBaTk8IT6dgjnGcJdSfA,633
11
+ cloudtoolbox-0.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
12
+ cloudtoolbox-0.1.0.dist-info/top_level.txt,sha256=lBiHHi76sKOBY-DmE0iDypxZxv-TTCnvHeiFleC_PuA,6
13
+ cloudtoolbox-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ cloud