Skip to main content

Reusable upload handler for PDFs, DOCX, PPTX, ZIPs

Project description

🗂️ PYZUP

PYZUP 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


📜 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzup-0.1.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyzup-0.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pyzup-0.1.2.tar.gz.

File metadata

  • Download URL: pyzup-0.1.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyzup-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a87ddea1ccd8fbf514112874185d89152778ab49402e2966b01d7972740a9635
MD5 8436423f88eab588fc1c885a6caef549
BLAKE2b-256 004cb2156dad6be9f78f547cbbc0430ad6a0bb1b7e4d8db7e7599a74c33bd99b

See more details on using hashes here.

File details

Details for the file pyzup-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyzup-0.1.2-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

Hashes for pyzup-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40272c9e612e31a1b3e39d5d43a85298e21747d2a2fe04b38c48859cfed3ea92
MD5 edd1d07708585a0730fa0f809461599e
BLAKE2b-256 c4b8bc99378785807b3a1693e85a9544c15b6ddf3337da11e9eacf2ce0b4e9d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page