A simple s3 storage service SDK tailored for Ascender Framework and it's DI.
Project description
Ascender MinIO SDK
Overview
The Ascender MinIO SDK is a storage service built for the Ascender Framework, supporting Amazon S3 and other S3-compatible storage providers. It integrates smoothly with Dependency Injection (DI) and simplifies common object storage tasks like:
- Uploading, downloading, and deleting files
- Managing buckets
- Generating pre-signed URLs
- Listing objects in a bucket
Installation
Create a new ascender framework project or use existing:
ascender new --name my_project
Navigate to the project directory:
cd my_project
To install the SDK with Poetry:
poetry add ascender-minio
Usage
1. Register MinIO in appBootstrap
In bootstrap.py:
from ascender.core.types import IBootstrap
from minio.minio_provider import provideMinio
appBootstrap: IBootstrap = {
"providers": [
provideMinio(
minio_endpoint="http://localhost:9000",
minio_access_key="your-access-key",
minio_secret_key="your-secret-key"
)
]
}
2. Inject MinioService into a Controller
In main_controller.py:
from ascender.core import Controller, Post, Get
from minio_service import MinioService
@Controller(standalone=False)
class MainController:
def __init__(self, minio_service: MinioService):
self.minio = minio_service
@Post("upload")
async def upload_file(self, bucket: str, key: str, data: bytes):
"""Upload a file to MinIO."""
return await self.minio.put_object(
Bucket=bucket, Key=key, Data=data,
ContentLength=len(data), ContentType="application/octet-stream"
)
@Get("download/{bucket}/{key}")
async def download_file(self, bucket: str, key: str):
"""Download a file from MinIO."""
return await self.minio.read_object(Bucket=bucket, Key=key)
@Get("list/{bucket}")
async def list_files(self, bucket: str):
"""List all files in a bucket."""
return await self.minio.list_objects(Bucket=bucket)
@Get("presigned/{bucket}/{key}")
async def generate_presigned_url(self, bucket: str, key: str):
"""Generate a pre-signed URL for a file."""
return await self.minio.generate_presigned_url(Bucket=bucket, Key=key)
@Post("delete/{bucket}/{key}")
async def delete_file(self, bucket: str, key: str):
"""Delete a file from MinIO."""
return await self.minio.remove_object(Bucket=bucket, Key=key)
3. Example Usage
Uploading a File
POST /upload
Content-Type: application/octet-stream
{
"bucket": "my-bucket",
"key": "file.txt",
"data": "SGVsbG8gV29ybGQh"
}
Downloading a File
GET /download/my-bucket/file.txt
Listing Files in a Bucket
GET /list/my-bucket
Generating a Pre-signed URL
GET /presigned/my-bucket/file.txt
Deleting a File
POST /delete/my-bucket/file.txt
This setup ensures clean DI-based injection without exposing the inner workings of MinioService.
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 ascender_minio-0.0.1.tar.gz.
File metadata
- Download URL: ascender_minio-0.0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0faa536501202a3bcac617ddc0f68d86aecb2369ad0b6c3629d051483c5dfd5
|
|
| MD5 |
59d2861de5d4d97ba4e5ea426c38cb56
|
|
| BLAKE2b-256 |
81c0cae5c7fb66a678be1dfc3e22abc9917180a5e254ef6cf99c1601aec74c14
|
File details
Details for the file ascender_minio-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ascender_minio-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd85f6db55e5372c8e03ddf366f9bae819fd2ddf56289187b3cb07c8d83fc2eb
|
|
| MD5 |
4cefafb606c6328f9ed6d4a3c73ca625
|
|
| BLAKE2b-256 |
46322a8e8d1f1ce3418b6b36cadef48d455601a8ee3d4b784ce0bb2cc989f144
|