Skip to main content

S3-compatible storage library with automatic fallback support

Project description

fallbacks3

S3-compatible storage library with automatic fallback for the upload process.

Installation

pip install fallbacks3

For development:

pip install -e .

Configuration

You must configure a comma-separated list of providers, as well as the scheme of the fallback provider, with environment variables named PROVIDERS and FALLBACK_PROVIDER.

# Comma-separated list of provider URIs
PROVIDERS="ps3://access_key:secret_key@ps3.palver.com,r2://access_key:secret_key@account.r2.cloudflarestorage.com"

# Fallback provider scheme (must be one of the providers in PROVIDERS)
FALLBACK_PROVIDER="r2"

Provider URI Format

Provider URIs follow the format:

<provider_scheme>://<access_key>:<secret_key>@<endpoint>

Examples: r2://key:secret@account.r2.cloudflarestorage.com, local://test:testkey@localhost:9000

Remote File URI Format

File URIs should specify the exact location from a provider bucket:

<provider>://<bucket>/<file_path>

Examples: ps3://palver-whatsapp/audio.mp3, s3://my-bucket/documents/report.pdf

Usage

from fallbacks3 import Storage

# Initialize storage using environment variables (PROVIDERS and FALLBACK_PROVIDER)
storage = Storage()

# Upload a local file to the provided remote path
stored_file_uri = storage.upload_file(
    remote_file_uri="ps3://palver-whatsapp/audio.mp3",
    local_file_path="/local/path/audio.mp3"
)
print(uri)  # "ps3://palver-whatsapp/audio.mp3"

# Async upload (for async environments)
stored_file_uri = await storage.upload_file_async(
    remote_file_uri="ps3://palver-whatsapp/audio.mp3",
    local_file_path="/local/path/audio.mp3"
)

# Download a file
downloaded_file_path = storage.download_file(
    remote_file_uri="ps3://palver-whatsapp/audio.mp3",
    local_file_path="/local/path/audio.mp3"
)
print(local_path)  # "/local/path/audio.mp3"

# Generate a signed URL for temporary access (default: 60 seconds)
signed_url = storage.generate_signed_url(
    remote_file_uri="ps3://palver-whatsapp/audio.mp3",
    expiration=3600
)
print(signed_url)  # "https://ps3.palver.com/palver-whatsapp/audio.mp3?signature=..."

Upload with Automatic Fallback

If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path), as to ensure files are not lost.

# If ps3 fails, automatically falls back to r2
stored_file_path = storage.upload_file(
    remote_file_uri="ps3://palver-whatsapp/audio.mp3",
    local_file_path="/local/path/audio.mp3"
)
# Returns "r2://palver-whatsapp/audio.mp3" if ps3 failed

Raises an exception if both primary and fallback providers fail.

Async Upload

For async environments, use upload_file_async():

import asyncio
from fallbacks3 import Storage

storage = Storage()

async def upload():
    stored_file_uri = await storage.upload_file_async(
        remote_file_uri="ps3://palver-whatsapp/audio.mp3",
        local_file_path="/local/path/audio.mp3"
    )
    print(stored_file_uri)  # "ps3://palver-whatsapp/audio.mp3"

asyncio.run(upload())

The async method also supports automatic fallback, just like the synchronous version.

Download and Signed URLs

Download and signed URL generation use the provider specified in the remote file URI.

Development

Install development dependencies:

pip install -e ".[dev]"

You can also develop with uv if available.

uv pip install -e ".[dev]"

Run tests:

pytest --cov=fallbacks3

# alternatively, with uv:
uv run pytest --cov=fallbacks3

Publishing to PyPI

The project is set up to be automatically uploaded to PyPI when a new tag is pushed. For a successful push, all tests must pass and the project must pass the check and format requirements.

One-time setup

Before publishing for the first time:

  1. Configure Trusted Publishing on PyPI:

You must have access to the pypi GitHub environment or be approved by required reviewers (milasd or giancarlopro) to publish.

Publishing a new version

  1. Update version in pyproject.toml
  2. Create and push a tag:
    git tag v[new version] # eg.: git tag v0.1.0
    git push origin v[new version] # eg.: git push origin v0.1.0
    

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

fallbacks3-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

fallbacks3-0.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file fallbacks3-0.2.0.tar.gz.

File metadata

  • Download URL: fallbacks3-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fallbacks3-0.2.0.tar.gz
Algorithm Hash digest
SHA256 01313eb6a7d82a438f646cd55ae9fb77d68910285a4fff2c1b21467723c1200c
MD5 11d249d579ec2ee9454a61ec5b9806e3
BLAKE2b-256 2e7d621746aa038a5b675033603c9753f2a9d43b17fe9af69c68daa8ace0214c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fallbacks3-0.2.0.tar.gz:

Publisher: publish.yaml on palverdata/fallbacks3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fallbacks3-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fallbacks3-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fallbacks3-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e7a6318d0bf753ebdbff49e5659f2054f0ae683c78a63837229bc07e5416ae4
MD5 e4d4883a77f2b2b0160d1f605b1111dc
BLAKE2b-256 30721038b52fefa08e86549505b5d5fac080a6ea7a991575c6b0d9034b903d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fallbacks3-0.2.0-py3-none-any.whl:

Publisher: publish.yaml on palverdata/fallbacks3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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