Reusable upload handler for PDFs, DOCX, PPTX, ZIPs
Project description
🗂️ PYPYZUP
PYPYZUP is a lightweight, reusable Python module designed to streamline file uploads in document-based applications. It supports single and multiple file uploads of:
- 📄 PDF (
.pdf) - 📊 PowerPoint (
.pptx) - 📝 Word (
.docx) - 📈 Excel (
.xlsx) - 🗜️ ZIP archives containing the above formats
PYZUP handles validation, safe extraction of ZIPs, automatic logging, and returns structured responses ideal for web APIs.
✅ Features
- Upload single or multiple files
- Validate ZIPs (must contain at least one allowed file)
- Logs disallowed or corrupt files cleanly
- Automatically creates target directories
- Daily rotating logs (JSON compressed + console)
- Structured response with
"success"and"error"lists
🧩 How to Use
from werkzeug.datastructures import FileStorage
from pathlib import Path
from PYZUP import handle_uploaded_file
file_objs = request.files.getlist("files") # Flask example
result = handle_uploaded_file(file_objs, Path("target_folder"))
if not result["success"]:
return jsonify({"error": "No valid files processed", "details": result["error"]}), 415
return jsonify(result), 200
📥 Example Response
{
"success": [
{"filename": "report.pdf", "message": "report.pdf uploaded successfully."},
{"filename": "slides.zip", "message": "ZIP extracted successfully."}
],
"error": [
{"filename": "malicious.exe", "message": "Allowed types: docx, pdf, pptx, xlsx, zip."}
]
}
⚙️ Flask Integration Example
from flask import Flask, request, jsonify
from pathlib import Path
from datetime import datetime
from PYZUP import handle_uploaded_file
from loguru import logger
app = Flask(__name__)
UPLOAD_ROOT = Path("uploaded_docs")
@app.route("/", methods=["POST"])
def upload():
files = request.files.getlist("files")
if not files:
return jsonify({"error": "No file part in request."}), 400
folder = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
target_dir = UPLOAD_ROOT / folder
result = handle_uploaded_file(files, target_dir)
return jsonify(result), 200
📁 Logging
Logs are stored in upload_logs/:
- Daily log files:
app_YYYYMMDD.log.zip - Console: logs shown at INFO level
- File logs: full tracebacks and debugging info
🔒 Validation Rules
- ✅ Allowed file types:
.pdf,.docx,.pptx,.xlsx,.zip - ✅ ZIP must contain at least one allowed file
- ⚠️ Unsupported ZIP contents are ignored and logged
- ❌ Empty filenames or invalid formats are rejected
👨💻 Authors
- Punit Tripathi (tripathi.punit@proton.me)
- Mohd. Amir (amir.zilli@gmail.com)
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
📌 Status
✅ Actively maintained, production-ready, and easy to integrate into Flask apps or other backends.
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 pyzup-0.1.1.tar.gz.
File metadata
- Download URL: pyzup-0.1.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b7895b0c4a983b18a6657468c2f6a6b23bfecffa2ed4910dc27ce276dfddead
|
|
| MD5 |
22f0dff1ba02e6cf0b55f7e8dc98fb78
|
|
| BLAKE2b-256 |
def204264894dcfbce5c20cbef2b47a1efd5b5f9a024108678fb50b7f3ff3f00
|
File details
Details for the file pyzup-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyzup-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44fc038dfd6df8d07bdd0a2f86c9e10b511dbe28541ec7b4789877514f2cf8ed
|
|
| MD5 |
4512e2ff8b9f12dab3cdadecea56c3bb
|
|
| BLAKE2b-256 |
6a90ec4debbc013df155c7872073449149d05f448fb337cdcf0e71f039b0d6c0
|