Skip to main content

A unified interface for AWS S3 and Google Cloud Storage operations

Project description

Cloud Storage Manager

A Python package for seamlessly managing file uploads across AWS S3 and Google Cloud Storage platforms.

Features

  • Unified interface for AWS S3 and Google Cloud Storage
  • Async operations support
  • Pre-signed URL generation
  • Easy file upload and deletion
  • Type-safe configuration using Pydantic
  • Comprehensive error handling
  • Logging support

Installation

pip install cloud-storage-manager

Quick Start

AWS S3 Example

import asyncio
from cloud_storage_manager import CloudStorageFactory, StorageProvider, StorageConfig, AwsConfig

async def main():
    # Configure AWS
    config = StorageConfig(
        aws=AwsConfig(
            bucket_name="my-bucket",
            access_key_id="your-access-key",
            secret_access_key="your-secret-key",
            region="us-east-1"  # optional, defaults to us-east-1
        )
    )
    
    # Create storage client
    storage = CloudStorageFactory.get_storage(StorageProvider.AWS, config)
    
    # Upload file
    cloud_path = await storage.upload("local/path/file.txt", "remote/path/file.txt")
    
    # Generate temporary URL
    url = await storage.get_public_url(cloud_path, expiration=3600)  # 1 hour expiration
    
    # Delete file
    success = await storage.delete(cloud_path)

asyncio.run(main())

Google Cloud Storage Example

import asyncio
from cloud_storage_manager import CloudStorageFactory, StorageProvider, StorageConfig, GcpConfig

async def main():
    # Configure GCP
    config = StorageConfig(
        gcp=GcpConfig(
            bucket_name="my-bucket",
            project_id="your-project-id",
            credentials={
                # Your service account credentials dictionary
            }
        )
    )
    
    # Create storage client
    storage = CloudStorageFactory.get_storage(StorageProvider.GCP, config)
    
    # Upload file
    cloud_path = await storage.upload("local/path/file.txt", "remote/path/file.txt")
    
    # Generate temporary URL
    url = await storage.get_public_url(cloud_path, expiration=3600)  # 1 hour expiration
    
    # Delete file
    success = await storage.delete(cloud_path)

asyncio.run(main())

Error Handling

The package provides specific exceptions for different types of errors:

from cloud_storage_manager import UploadError, DeleteError, DownloadError

try:
    await storage.upload("file.txt", "remote/file.txt")
except UploadError as e:
    print(f"Upload failed: {e}")

Configuration

AWS Configuration

  • bucket_name: Name of your S3 bucket
  • access_key_id: AWS access key ID
  • secret_access_key: AWS secret access key
  • region: AWS region (optional, defaults to us-east-1)

GCP Configuration

  • bucket_name: Name of your GCP bucket
  • project_id: Your GCP project ID
  • credentials: Service account credentials dictionary

Development

To contribute to the project:

# Clone the repository
git clone https://github.com/yourusername/cloud-storage-manager.git

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

cloud_storage_manager-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

cloud_storage_manager-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file cloud_storage_manager-0.1.0.tar.gz.

File metadata

  • Download URL: cloud_storage_manager-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for cloud_storage_manager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bde41745a2bf9a425246ee3c392b4827756fabc7d2cf869a7e7c804fe124c990
MD5 4da44ae08fa95f1675f986c8556dcce2
BLAKE2b-256 8e9866869049e864084900959fafb0d765c3f4b434d035306431ef926b889454

See more details on using hashes here.

File details

Details for the file cloud_storage_manager-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloud_storage_manager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f727eb9503d3c870ebb82d0d0664c89961d46820e8a7b0e532d24361d382955
MD5 f2e0624b9cc7af69f6d58d9969d6dcdb
BLAKE2b-256 0809b6ba41d2b0d582ac8eac76609c7aeb77ac0bb90dd4047b2dd7a3e23d61bf

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