BoostedBlob
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
- breaking The generic `boostedblob.Path` object was removed in v1.0.0. You must now use specific path types: `LocalPath`, `GooglePath`, or `AzurePath` imported from `boostedblob.path`.
- breaking Specific operations like `read_json`, `write_json`, `copy`, and `move` were moved from top-level `boostedblob` imports to dedicated submodules in v1.0.0.
- breaking The return type of `list_dir` changed from `AsyncIterator[str]` to `AsyncIterator[boostedblob.path.BasePath]` in v1.0.0.
- gotcha As of v1.0.0, `boostedblob.path.BasePath` objects are immutable. Modifying their attributes directly is no longer possible.
Install
-
pip install boostedblob -
pip install boostedblob[gcs,azure]
Imports
- LocalPath, AzurePath, GooglePath
from boostedblob.path import LocalPath, AzurePath, GooglePath
- read_json, write_json
from boostedblob.read import read_json from boostedblob.write import write_json
- delete, list_dir
from boostedblob import delete, list_dir
Quickstart
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())