wdg-file-storage
wdg-file-storage is a Python package that simplifies interactions with S3-compatible storage systems. It provides a reusable and extendable client for operations such as file upload, download, and presigned URL generation. Designed with scalability and testability in mind, this package is ideal for multi-account and multi-region setups.
Features
- Upload and Download Files: Seamlessly manage file transfers to and from S3 buckets.
- Generate Presigned URLs: Create time-limited URLs for secure file access.
- Lazy Initialization: Efficient resource management by initializing the S3 client only when needed.
- Custom Session Management: Support for multi-account and multi-region setups with custom
boto3.Sessioninstances. - Thread-Safe Singleton Design: Ensures a single instance for consistent client usage.
Utils and Helper Function
- save_files_meta_data Save files meta data with dynamic model
Requirements
- Python 3.8+
boto3- Django (to access
settingsmodule)
Installation
Install the package using pip:
pip install wdg-file-storage
Configuration
Add the following required settings in your Django project's settings.py:
S3_ENDPOINT_URL = "your-s3-endpoint-url"
S3_ACCESS_KEY_ID = "your-access-key-id"
S3_SECRET_ACCESS_KEY = "your-secret-access-key"
Usage
Default Client
Upload a File
from wdg_file_storage import S3Client
s3_client = S3Client()
s3_client.upload_file("my_bucket", "example.txt", b"File content here")
Generate a Presigned URL
url = s3_client.generate_presigned_url(
bucket_name="my_bucket",
key="example.txt",
method="get_object",
expiry=3600
)
print(f"Presigned URL: {url}")
Download a File
file_data = s3_client.download_file("my_bucket", "example.txt")
print(file_data.decode())
Custom Session
Use a Custom boto3 Session
from boto3.session import Session
from wdg_file_storage import S3Client
custom_session = Session(
aws_access_key_id="custom_access_key",
aws_secret_access_key="custom_secret_key",
region_name="custom_region"
)
s3_client = S3Client(session=custom_session)
s3_client.upload_file("custom_bucket", "example.txt", b"File content here")
List Files in a Bucket
files = s3_client.list_files("my_bucket")
print(files)
Development
Clone the Repository
git clone https://github.com/yourusername/wdg-file-storage.git
cd wdg-file-storage
Install Dependencies
pip install -r requirements.txt
Run Tests
To ensure everything is working as expected:
pytest
Publishing to PyPI
- Update
setup.pywith the correct package information. - Build the distribution:
python setup.py sdist bdist_wheel
- Upload to PyPI using
twine:
twine upload dist/*
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request to contribute to this project.
Contact
For issues or inquiries, please contact [your-email@example.com].
Metadata
Release files for wdg-file-storage 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wdg-file-storage-0.2.0.tar.gz | 13.3 kB | Without provenance | Details for wdg-file-storage-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wdg_file_storage-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for wdg_file_storage-0.2.0-py3-none-any.whl |
Total release size: 31.1 kB
Release files / wdg-file-storage-0.2.0.tar.gz
| Download URL | wdg-file-storage-0.2.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c26e9c1bd3bef24acd0b8b3744dd865d8a5516ac276a2f5c05676e0d86ffed6
|
|
BLAKE2b-256 checksum How to use checksums |
853b966538ac7fc742f1fddd5af1da8a85896e636a274d9bed02ba52b58bee86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Release files / wdg_file_storage-0.2.0-py3-none-any.whl
| Download URL | wdg_file_storage-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ff0fccf80de493d8879da524927afa7cb83e172c6fb50194f677c145f1f00de
|
|
BLAKE2b-256 checksum How to use checksums |
afdd0e1d594b345a00c04f34325e17458626e0fb66b32692cfae7dfec6585273
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Security for wdg-file-storage 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.