A Python package for AWS S3 utilities
Project description
PYAWS_S3
Description
S3Client is a Python class that simplifies interaction with AWS S3 for uploading, managing, and deleting files. It supports uploading images, DataFrames, PDFs, and generating pre-signed URLs.
Installation
Make sure you have installed:
pip install pyaws_s3
Env Variabiles
Make sure to add this environment variable:
AWS_ACCESS_KEY_ID=<Your Access Key Id>
AWS_SECRET_ACCESS_KEY=<Your Secrect Access Key>
AWS_REGION=<Your Region>
AWS_BUCKET_NAME=<Your Bucket Name>
```bash
## Usage
### Initialization
You can initialize the class by passing AWS credentials as parameters or via environment variables:
```python
from s3_client import S3Client
s3 = S3Client(
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
region_name=os.getenv("AWS_REGION"),
bucket_name=os.getenv("AWS_BUCKET_NAME")
)
Main Methods
1. upload_image(fig, object_name, format_file=Literal["png", "jpeg", "svg", "html"])
Uploads a figure (e.g., Matplotlib or Plotly) to S3 as an image (svg, png, jpeg, html).
url = s3.upload_image(fig, "folder/image.svg", format_file="svg")
2. upload_from_dataframe(df, object_name, format_file=Literal["xlsx", "csv", "pdf"])
Uploads a DataFrame to S3 as an Excel, CSV, or PDF file.
url = s3.upload_from_dataframe(df, "folder/data", format_file="csv")
3. upload_to_pdf(text, object_name)
Exports text to PDF and uploads it to S3.
url = s3.upload_to_pdf("Text to export", "folder/file.pdf")
4. await delete_all(filter=None)
Deletes all files from the bucket, optionally filtering by name.
import asyncio
await s3.delete_all(filter="your_filter")
Notes
- All upload methods return a pre-signed URL for downloading the file.
- Integrated error handling with logging.
- For uploading images and DataFrames, utility functions are required (
bytes_from_figure,html_from_figure).
Complete Example
import matplotlib.pyplot as plt
import pandas as pd
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
s3 = S3Client(bucket_name="my-bucket")
img_url = s3.upload_image(fig, "test.svg")
df_url = s3.upload_from_dataframe(df, "mydata")
pdf_url = s3.upload_to_pdf("Hello PDF", "hello.pdf")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyaws_s3-1.0.1.tar.gz.
File metadata
- Download URL: pyaws_s3-1.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c86c2524e336b643a28ed618dd7b5afae1aecbb3ebfabe6725921d67b543ef2f
|
|
| MD5 |
b69ee52d167a8d756c72b90ee7f08e9b
|
|
| BLAKE2b-256 |
9253213fcccf312c0f1cab6d8fef0e8b6dde5036c4445456e2656b51d5b7714a
|
File details
Details for the file pyaws_s3-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pyaws_s3-1.0.1-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55932249dc428024e9b9ac59db7d979f0f2a78ba2323ed867057352e12aaa2a6
|
|
| MD5 |
23f1654e2b9671e529ecd1f489c1c04f
|
|
| BLAKE2b-256 |
653e8d857a3fc148e6fc69657a5bd36fa9932dcc04afd7ab4e2e928ece17a44a
|