Skip to main content

Python SDK for FileZen file management service

Project description

FileZen Python SDK

A Python SDK for FileZen, providing easy file upload and management capabilities.

Features

  • File Upload: Upload single files efficiently
  • Bulk Upload: Upload multiple files concurrently
  • URL Upload: Upload files directly from URLs
  • Signed URLs: Generate secure signed URLs for direct uploads
  • Multipart Upload: Automatic multipart upload for large files (>10MB)
  • File Deletion: Delete files by URL
  • Error Handling: Comprehensive error handling and retry logic
  • Backend Optimized: Designed for server-side usage without UI dependencies

Installation

pip install filezen-python

Quick Start

import asyncio
from filezen import ZenStorage

async def main():
    # Initialize storage
    storage = ZenStorage({
        "api_key": "your_api_key_here",  # Optional: can use FILEZEN_API_KEY env var
    })

    # Upload a single file
    with open("my_file.jpg", "rb") as f:
        upload = await storage.upload(f.read(), {
            "name": "my_file.jpg",
            "mime_type": "image/jpeg",
        })
        print(f"File uploaded: {upload.file.url}")

    # Upload multiple files
    uploads = await storage.bulk_upload(
        {"source": file1_content, "options": {"name": "file1.jpg"}},
        {"source": file2_content, "options": {"name": "file2.png"}},
    )

    # Generate a signed URL
    signed_url = storage.generate_signed_url({
        "file_key": "my_file.jpg",
        "expires_in": 3600,  # 1 hour
    })

asyncio.run(main())

Multipart Upload

The SDK automatically uses multipart upload for files larger than 10MB. This provides:

  • Resumable uploads: Upload can be resumed if interrupted
  • Better performance: Parallel chunk uploads
  • Progress tracking: Detailed progress for each chunk
  • Error recovery: Automatic retry for failed chunks
# Large files are automatically handled with multipart upload
with open("large_video.mp4", "rb") as f:
    upload = await storage.upload(f.read(), {
        "name": "large_video.mp4",
        "mime_type": "video/mp4",
    })
    # Automatically uses multipart upload for files > 10MB

Configuration

storage = ZenStorage({
    "api_key": "your_api_key",  # FileZen API key
    "api_url": "https://api.filezen.dev",  # API base URL
    "keep_uploads": True,  # Whether to track uploads in memory
})

Environment Variables

You can also set configuration via environment variables:

export FILEZEN_API_KEY="your_api_key_here"
export FILEZEN_API_URL="https://api.filezen.dev"  # Optional

API Reference

ZenStorage

Main storage class for FileZen operations.

Methods

  • upload(source: bytes, options: dict) -> ZenUpload: Upload a single file
  • bulk_upload(*uploads: dict) -> List[ZenUpload]: Upload multiple files
  • generate_signed_url(options: dict) -> str: Generate a signed URL
  • delete_by_url(url: str) -> bool: Delete a file by URL

ZenUpload

Represents a file upload operation.

Properties

  • file: ZenFile: Uploaded file information
  • error: ZenError: Upload error if any
  • is_completed: bool: Whether upload is completed
  • is_cancelled: bool: Whether upload is cancelled

Methods

  • upload() -> ZenUpload: Perform the upload operation
  • cancel(): Cancel the upload

Examples

See the FastAPI example app for a complete implementation with web interface.

Documentation

For detailed documentation, visit docs.filezen.dev

License

MIT License

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

filezen_python-0.1.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

filezen_python-0.1.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for filezen_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f82e4555a2a0a1bb7535c95457d4be959dc65636ca403b86b36d9ebb48fadc4a
MD5 fd0898ea8d44f515cdc51cc683c14c09
BLAKE2b-256 c1b9ba5b09f07e50993e1ea8c1fc31f007de50436859432ca5cba6e03c382d0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: filezen_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for filezen_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c18d141ccbbb79b950f4a19a0da47586bf5f979552d51633365117601d5b5e0
MD5 db0d188a9f7a9f211497a7a0208324c2
BLAKE2b-256 58a78256184981509c2bfc476b3198a98d3f6838978abd11f82a46cb4b075f77

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