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"

# 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.

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.1.0.tar.gz (7.6 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.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fallbacks3-0.1.0.tar.gz
Algorithm Hash digest
SHA256 559d5662e3cfa224c20b99d1b272f34f596dbfff110b4c7a94238d51752ed087
MD5 08442cfbd009d788d4066483d02b8f60
BLAKE2b-256 395eafb21bb8a42cbbe99d765eac2384d7713b35a523d9a683091a27cbdc2b4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for fallbacks3-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: fallbacks3-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c15eae5e8a52b179ca1a32990bdd0fa3d0864c2903be64cde215c846ff7e2c71
MD5 e1ca7de52507aae63f6d169e54837897
BLAKE2b-256 c858818beabd5917aca18c37a21d9ca84e6015787b20cda5cbb5c63cb33560a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for fallbacks3-0.1.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