BoostedBlob

1.0.0 · active · verified Thu Apr 09

BoostedBlob is a Python library and command-line tool designed for efficient, async-first file operations across local filesystems, Google Cloud Storage, and Azure Blob Storage. It provides a unified API for common tasks like copying, moving, listing, reading, and writing files. The current version is 1.0.0, which introduced significant API changes, moving from a single generic `Path` object to specific `LocalPath`, `GooglePath`, and `AzurePath` types. Its primary release cadence has been irregular but reached a stable `1.0.0` in April 2024.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic file operations for local paths, and conditional operations for Azure Blob Storage. To run the Azure part, set `AZURE_STORAGE_ACCOUNT_NAME` and `AZURE_STORAGE_CONTAINER` environment variables. For Google Cloud Storage, ensure `boostedblob[gcs]` is installed and set `GOOGLE_APPLICATION_CREDENTIALS` and `GCS_BUCKET_NAME`.

import asyncio
import os
from boostedblob.path import LocalPath, AzurePath
from boostedblob import delete, list_dir
from boostedblob.read import read_json
from boostedblob.write import write_json

async def main():
    # 1. Local File Operations
    print("--- Local File Operations ---")
    local_path = LocalPath("./boostedblob_quickstart_test.json")
    try:
        await write_json({"message": "Hello from BoostedBlob local!"}, local_path)
        print(f"Wrote to {local_path}")
        content = await read_json(local_path)
        print(f"Read from {local_path}: {content}")
        # Clean up
        await delete(local_path)
        print(f"Deleted {local_path}")
    except Exception as e:
        print(f"Error during local operations: {e}")

    # 2. Azure Blob Storage Operations (requires environment variables)
    print("\n--- Azure Blob Storage Operations ---")
    azure_account = os.environ.get('AZURE_STORAGE_ACCOUNT_NAME')
    azure_container = os.environ.get('AZURE_STORAGE_CONTAINER')

    if azure_account and azure_container:
        # Example Azure path
        azure_path = AzurePath(f"az://{azure_account}/{azure_container}/boostedblob_quickstart_azure.json")
        print(f"Target Azure Path: {azure_path}")
        try:
            await write_json({"message": "Hello from BoostedBlob Azure!"}, azure_path)
            print(f"Wrote to {azure_path}")
            content = await read_json(azure_path)
            print(f"Read from {azure_path}: {content}")
            # Uncomment the line below to delete the file after reading
            # await delete(azure_path)
            # print(f"Deleted {azure_path}")
            print("Azure operations completed. (Deletion is commented out for safety).")
        except Exception as e:
            print(f"Azure operations failed (check credentials, account, container, permissions): {e}")
    else:
        print("Skipping Azure operations: Set AZURE_STORAGE_ACCOUNT_NAME and AZURE_STORAGE_CONTAINER environment variables to enable.")
        print("For GCS, install with `boostedblob[gcs]` and set `GOOGLE_APPLICATION_CREDENTIALS` and `GCS_BUCKET_NAME`.")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →