Metadata-Version: 2.4
Name: simple_module_file_storage
Version: 0.0.4
Summary: Pluggable file upload + storage (local or S3 via extras) module for simple_module apps
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
Project-URL: Repository, https://github.com/antosubash/simple_module_python
Project-URL: Issues, https://github.com/antosubash/simple_module_python/issues
Project-URL: Changelog, https://github.com/antosubash/simple_module_python/blob/main/CHANGELOG.md
Author-email: Anto Subash <antosubash@live.com>
License-Expression: MIT
License-File: LICENSE
Keywords: file-upload,s3,simple-module,storage
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: aiofiles>=23
Requires-Dist: simple-module-core==0.0.4
Requires-Dist: simple-module-db==0.0.4
Requires-Dist: simple-module-hosting==0.0.4
Provides-Extra: s3
Requires-Dist: aioboto3>=13; extra == 's3'
Description-Content-Type: text/markdown

# simple_module_file_storage

Pluggable file-upload + storage module for [simple_module](https://github.com/antosubash/simple_module_python) apps. Defaults to local-disk storage for development; install the `[s3]` extra to switch to any S3-compatible backend via `aioboto3`.

## Install

```bash
# local-disk storage (dev default)
pip install simple_module_file_storage

# S3-compatible storage (production)
pip install "simple_module_file_storage[s3]"
```

## What it provides

- `POST /api/files` upload endpoint with multipart + metadata.
- `GET /api/files/{id}` signed-URL or stream download.
- Pluggable backend via `SM_FILE_STORAGE_BACKEND` (`local` | `s3`).
- S3 config via `SM_FILE_STORAGE_S3_BUCKET`, `SM_FILE_STORAGE_S3_ENDPOINT` (for R2/MinIO/etc.), `SM_FILE_STORAGE_S3_REGION`.

## Usage

From another module:

```python
from file_storage.service import FileStorageService   # type: ignore[import-not-found]

async def attach_receipt(
    svc: FileStorageService = Depends(FileStorageService),
    upload: UploadFile = File(...),
):
    record = await svc.save(upload, folder="receipts/")
    return {"file_id": record.id, "url": record.url}
```

Env config (example, S3):

```
SM_FILE_STORAGE_BACKEND=s3
SM_FILE_STORAGE_S3_BUCKET=my-app-uploads
SM_FILE_STORAGE_S3_REGION=us-east-1
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
```

## Depends on

- `simple_module_core`, `simple_module_db`, `simple_module_hosting`
- `aiofiles`
- Optional: `aioboto3` (install the `[s3]` extra)

## License

MIT — see [LICENSE](https://github.com/antosubash/simple_module_python/blob/main/LICENSE).
