Multi-Storage Client (MSC)

0.46.0 · active · verified Tue Apr 14

The Multi-Storage Client (MSC) is a unified, high-performance Python client designed for seamless interaction with various object and file stores, including AWS S3, Azure Blob Storage, Google Cloud Storage (GCS), NVIDIA AIStore, Oracle Cloud Infrastructure (OCI) Object Storage, and POSIX file systems. It offers a generic interface, simplifying data access and enabling storage location changes without extensive code modifications. As of its current version 0.46.0, it maintains an active release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `StorageClient` using a YAML configuration file and perform basic file operations (write, read, list) with a local POSIX storage profile. Authentication for cloud providers is typically managed within the YAML profiles or via environment variables, avoiding hardcoding in Python code.

import os
import yaml
from multistorageclient.client import StorageClient

# Create a dummy MSC configuration file for local testing
config_content = '''
profiles:
  local-files:
    storage_provider:
      type: posix
      options:
        base_path: ./msc_data
'''

# Create a directory for local files
os.makedirs('./msc_data', exist_ok=True)

config_path = './msc_config.yaml'
with open(config_path, 'w') as f:
    f.write(config_content)

# Set the MSC_CONFIG environment variable to point to the config file
os.environ['MSC_CONFIG'] = config_path

try:
    # Instantiate the client
    client = StorageClient()

    # Example: Write a file using the 'local-files' profile
    local_file_path = 'msc://local-files/example.txt'
    with client.open(local_file_path, 'w') as f:
        f.write('Hello from Multi-Storage Client!')
    print(f"Content written to {local_file_path}")

    # Example: Read the file
    with client.open(local_file_path, 'r') as f:
        content = f.read()
    print(f"Content read from {local_file_path}: {content}")

    # Example: List objects in the 'local-files' profile
    objects = client.list_objects('msc://local-files/')
    print("Objects in 'msc://local-files/':")
    for obj in objects:
        print(f"- {obj.uri}")

finally:
    # Clean up the dummy config file and data directory
    if os.path.exists(config_path):
        os.remove(config_path)
    if os.path.exists('./msc_data/example.txt'):
        os.remove('./msc_data/example.txt')
    if os.path.exists('./msc_data'):
        os.rmdir('./msc_data')
    del os.environ['MSC_CONFIG']

view raw JSON →