pyaws-s3 1.0.5__tar.gz → 1.0.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyaws_s3
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: A Python package for AWS S3 utilities
5
5
  Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
6
6
  Keywords: aws,s3,utilities
@@ -31,7 +31,7 @@ Requires-Dist: matplotlib==3.10.3
31
31
  Requires-Dist: multidict==6.4.3
32
32
  Requires-Dist: narwhals==1.39.1
33
33
  Requires-Dist: numpy==2.2.5
34
- Requires-Dist: packaging==24.2
34
+ Requires-Dist: packaging==23.2
35
35
  Requires-Dist: pandas==2.2.3
36
36
  Requires-Dist: pillow==11.2.1
37
37
  Requires-Dist: plotly==6.1.0
@@ -5,9 +5,9 @@ import aioboto3
5
5
  import pandas as pd
6
6
  import io
7
7
  import matplotlib.pyplot as plt
8
+ from plotly.graph_objs import Figure
8
9
  from pandas.plotting import table
9
10
  from typing import Any, Literal
10
- from util import bytes_from_figure, html_from_figure
11
11
  from fpdf import FPDF
12
12
 
13
13
  logger = logging.getLogger(__name__)
@@ -39,6 +39,48 @@ class S3Client:
39
39
  self.region_name = kwargs.get("region_name", os.getenv("AWS_REGION"))
40
40
  self.bucket_name = kwargs.get("bucket_name", os.getenv("AWS_BUCKET_NAME"))
41
41
 
42
+ def _bytes_from_figure(self, f: Figure, **kwargs) -> bytes:
43
+ """
44
+ Convert a Plotly Figure to a PNG image as bytes.
45
+
46
+ Args:
47
+ f (Figure): The Plotly Figure object to be converted.
48
+
49
+ Returns:
50
+ bytes: The PNG image data as bytes.
51
+ :param f: The Plotly Figure object to be converted into a PNG image.
52
+ """
53
+
54
+ format_file = kwargs.get("format_file", "png") # The format of the image to be converted to
55
+ width = kwargs.get("width", 640) # The width of the image in pixels
56
+ height = kwargs.get("height", 480) # The height of the image in pixels
57
+
58
+ with io.BytesIO() as bytes_buffer:
59
+ f.write_image(bytes_buffer,
60
+ format=format_file,
61
+ width = width,
62
+ height = height) # Write the figure to the bytes buffer as a PNG image
63
+ bytes_buffer.seek(0) # Reset the buffer position to the beginning
64
+ return bytes_buffer.getvalue() # Return the bytes data
65
+
66
+ def _html_from_figure(self, f: Figure) -> str:
67
+ """
68
+ Convert a Plotly Figure to an HTML string.
69
+
70
+ Args:
71
+ f (Figure): The Plotly Figure object to be converted.
72
+
73
+ Returns:
74
+ str: The HTML representation of the figure as a string.
75
+ """
76
+ with io.BytesIO() as bytes_buffer:
77
+ # Wrap the BytesIO with a TextIOWrapper to handle strings
78
+ with io.TextIOWrapper(bytes_buffer, encoding='utf-8') as text_buffer:
79
+ f.write_html(text_buffer) # Write the figure to the text buffer
80
+ text_buffer.flush() # Ensure all data is written
81
+ bytes_buffer.seek(0) # Reset the buffer position to the beginning
82
+ return bytes_buffer.getvalue().decode('utf-8') # Decode bytes to string and return
83
+
42
84
  async def _get_s3_client_async(self) -> Any:
43
85
  """
44
86
  Get an asynchronous S3 client using the provided AWS credentials and region.
@@ -178,12 +220,12 @@ class S3Client:
178
220
 
179
221
  if format_file == "html":
180
222
  # Convert the figure to SVG
181
- file_text = html_from_figure(fig)
223
+ file_text = self._html_from_figure(fig)
182
224
  # Upload the html text to s3
183
225
  s3_resource.Bucket(self.bucket_name).Object(object_name).put(Body=file_text, ContentType=mimetypes)
184
226
  else:
185
227
  # Convert the figure to bytes
186
- file_buffer = bytes_from_figure(fig, format_file=format_file)
228
+ file_buffer = self._bytes_from_figure(fig, format_file=format_file)
187
229
  # Upload the image bytes to S3
188
230
  s3_resource.Bucket(self.bucket_name).Object(object_name).put(Body=file_buffer, ContentType=mimetypes)
189
231
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyaws_s3
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: A Python package for AWS S3 utilities
5
5
  Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
6
6
  Keywords: aws,s3,utilities
@@ -31,7 +31,7 @@ Requires-Dist: matplotlib==3.10.3
31
31
  Requires-Dist: multidict==6.4.3
32
32
  Requires-Dist: narwhals==1.39.1
33
33
  Requires-Dist: numpy==2.2.5
34
- Requires-Dist: packaging==24.2
34
+ Requires-Dist: packaging==23.2
35
35
  Requires-Dist: pandas==2.2.3
36
36
  Requires-Dist: pillow==11.2.1
37
37
  Requires-Dist: plotly==6.1.0
@@ -3,7 +3,6 @@ README.md
3
3
  pyproject.toml
4
4
  pyaws_s3/__init__.py
5
5
  pyaws_s3/s3.py
6
- pyaws_s3/util.py
7
6
  pyaws_s3.egg-info/PKG-INFO
8
7
  pyaws_s3.egg-info/SOURCES.txt
9
8
  pyaws_s3.egg-info/dependency_links.txt
@@ -20,7 +20,7 @@ matplotlib==3.10.3
20
20
  multidict==6.4.3
21
21
  narwhals==1.39.1
22
22
  numpy==2.2.5
23
- packaging==24.2
23
+ packaging==23.2
24
24
  pandas==2.2.3
25
25
  pillow==11.2.1
26
26
  plotly==6.1.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyaws_s3"
7
- version = "1.0.5"
7
+ version = "1.0.7"
8
8
  description = "A Python package for AWS S3 utilities"
9
9
  authors = [
10
10
  { name="Giuseppe Zileni", email="giuseppe.zileni@gmail.com" }
@@ -37,7 +37,7 @@ dependencies = [
37
37
  "multidict==6.4.3",
38
38
  "narwhals==1.39.1",
39
39
  "numpy==2.2.5",
40
- "packaging==24.2",
40
+ "packaging==23.2",
41
41
  "pandas==2.2.3",
42
42
  "pillow==11.2.1",
43
43
  "plotly==6.1.0",
@@ -1,47 +0,0 @@
1
- import io
2
- import logging
3
- from plotly.graph_objs import Figure
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
- def bytes_from_figure(f: Figure, **kwargs) -> bytes:
8
- """
9
- Convert a Plotly Figure to a PNG image as bytes.
10
-
11
- Args:
12
- f (Figure): The Plotly Figure object to be converted.
13
-
14
- Returns:
15
- bytes: The PNG image data as bytes.
16
- :param f: The Plotly Figure object to be converted into a PNG image.
17
- """
18
-
19
- format_file = kwargs.get("format_file", "png") # The format of the image to be converted to
20
- width = kwargs.get("width", 640) # The width of the image in pixels
21
- height = kwargs.get("height", 480) # The height of the image in pixels
22
-
23
- with io.BytesIO() as bytes_buffer:
24
- f.write_image(bytes_buffer,
25
- format=format_file,
26
- width = width,
27
- height = height) # Write the figure to the bytes buffer as a PNG image
28
- bytes_buffer.seek(0) # Reset the buffer position to the beginning
29
- return bytes_buffer.getvalue() # Return the bytes data
30
-
31
- def html_from_figure(f: Figure) -> str:
32
- """
33
- Convert a Plotly Figure to an HTML string.
34
-
35
- Args:
36
- f (Figure): The Plotly Figure object to be converted.
37
-
38
- Returns:
39
- str: The HTML representation of the figure as a string.
40
- """
41
- with io.BytesIO() as bytes_buffer:
42
- # Wrap the BytesIO with a TextIOWrapper to handle strings
43
- with io.TextIOWrapper(bytes_buffer, encoding='utf-8') as text_buffer:
44
- f.write_html(text_buffer) # Write the figure to the text buffer
45
- text_buffer.flush() # Ensure all data is written
46
- bytes_buffer.seek(0) # Reset the buffer position to the beginning
47
- return bytes_buffer.getvalue().decode('utf-8') # Decode bytes to string and return
File without changes
File without changes
File without changes
File without changes