Quickstart¶
Configuration¶
The MSC can be used without any configuration to access POSIX paths. When no configuration is provided, it uses a default profile that enables basic file system operations:
# Using full imports
from multistorageclient import StorageClient, StorageClientConfig
# Create a client with default POSIX profile
client = StorageClient(StorageClientConfig.from_file())
# Access local files
client.read("/path/to/file.txt")
# Using msc shortcut
import multistorageclient as msc
# Access local files
with msc.open("/path/to/file.txt", "r") as f:
print(f.read())
For more advanced usage, you’ll want to create an MSC configuration. This configuration defines profiles which define provider configurations for different storage backends like S3, GCS, etc.
Note
When using POSIX paths, only absolute paths (starting with “/”) are supported.
File-Based¶
File-based configurations can be written in YAML or JSON format. The MSC will search for configuration files in the following locations (in order):
Path specified by
MSC_CONFIG
environment variable/etc/msc_config.yaml
or/etc/msc_config.json
~/.config/msc/config.yaml
or~/.config/msc/config.json
~/.msc_config.yaml
or~/.msc_config.json
You can explicitly specify a configuration file by setting the MSC_CONFIG
environment variable:
export MSC_CONFIG=/path/to/my/config.yaml
1profiles:
2 my-profile:
3 storage_provider:
4 type: s3
5 options:
6 base_path: my-bucket
7 metadata_provider:
8 type: manifest
9 options:
10 manifest_path: .msc_manifests
1{
2 "profiles": {
3 "my-profile": {
4 "storage_provider": {
5 "type": "s3",
6 "options": {
7 "base_path": "my-bucket"
8 }
9 },
10 "metadata_provider": {
11 "type": "manifest",
12 "options": {
13 "manifest_path": ".msc_manifests"
14 }
15 }
16 }
17 }
18}
Each profile object configures the providers and options for a storage client. The schema includes provider types, options, and optional provider bundles.
See Configuration Reference for the complete configuration schema.
Dictionary-Based¶
Note
This option can only be used if you create multistorageclient.StorageClient
instances directly.
See Object/File Operations for the different ways to interact with MSC.
Dictionary-based configurations use Python dictionaries with multistorageclient.StorageClientConfig.from_dict()
.
The schema is the same as file-based configurations.
1from multistorageclient import StorageClient, StorageClientConfig
2
3config = StorageClientConfig.from_dict(
4 config_dict={
5 "profiles": {
6 "my-profile": {
7 "storage_provider": {
8 "type": "s3",
9 "options": {
10 "base_path": "my-bucket"
11 }
12 }
13 }
14 }
15 }
16)
17
18client = StorageClient(config=config)
Rclone-Based¶
MSC also supports using an rclone configuration file as the source for MSC profiles. This is particularly useful if you already have an rclone configuration file and want to leverage the same profiles for MSC.
In an rclone configuration file, profiles are defined as INI sections, and the keys follow rclone’s naming conventions. MSC will parse these files to create the corresponding provider configurations.
1[my-profile]
2type = s3
3base_path = my-bucket
4access_key_id = my-access-key-id
5secret_key_id = my-secret-key-id
6endpoint = https://my-endpoint
7region = us-east-1
MSC checks for rclone-based configurations with the following priority:
The same directory as the
rclone
executable (if found inPATH
).XDG_CONFIG_HOME/rclone/rclone.conf
(ifXDG_CONFIG_HOME
is set)./etc/rclone.conf
~/.config/rclone/rclone.conf
~/.rclone.conf
Note
MSC File-Based configuration uses different configuration keys than rclone. For example, MSC uses endpoint_url
for multistorageclient.StorageClient.S3StorageProvider
but rclone expects endpoint
. MSC aligns with rclone defaults so that if you have a rclone configuration, you can use it with MSC without any modifications on existing keys.
Note
Rclone configuration primarily focus on storage access. Some MSC features such as caching and observability cannot be enabled with a rclone configuration. Therefore, MSC allows to use a rclone-based configuration for storage acceess alongside with a built-in File-Based configuration for additional features. You can also use the built-in file-based configuration to add extra parameters to an individual profile such as metadata_provider
.
Object/File Operations¶
There’s 3 ways to interact with MSC:
Shortcut functions in the
multistorageclient
module.The
multistorageclient.StorageClient
class.
Shortcuts¶
Shortcuts automatically create and manage multistorageclient.StorageClient
instances for you.
They only support file-based configuration.
1import multistorageclient as msc
2
3# Create a client for the data-s3-iad profile and open a file.
4file = msc.open(url="msc://data-s3-iad/animal-photos/giant-panda.png")
5
6# Reuse the client for the data-s3-iad profile and download a file.
7msc.download_file(
8 url="msc://data-s3-iad/animal-photos/red-panda.png",
9 local_path="/tmp/animal-photos/red-panda.png"
10)
Shortcuts use msc://{profile name}/{file/object path relative to the storage provider's base path}
URLs for file/object paths.
See multistorageclient
for all shortcut methods.
Clients¶
There may be times when you want to create and manage clients by yourself for programmatic configuration or manual lifecycle control instead of using shortcuts.
You can create multistorageclient.StorageClientConfig
and multistorageclient.StorageClient
instances directly.
1from multistorageclient import StorageClient, StorageClientConfig
2
3# Use a file-based configuration.
4config = StorageClientConfig.from_file()
5
6# Use a dictionary-based configuration.
7config = StorageClientConfig.from_dict(
8 config_dict={
9 "profiles": {
10 "my-profile": {
11 "storage_provider": {
12 "type": "s3",
13 "options": {
14 "base_path": "my-bucket"
15 }
16 }
17 }
18 }
19 },
20 profile="my-profile",
21)
22
23# Create a client
24client = StorageClient(config=config)
25
26# Open a file
27file = client.open("animal-photos/red-panda.png")
Clients use file/object paths relative to the storage provider’s base path.