Skip to content

Configure from settings

get_storage is already settings-driven: it reads STORIX_PROVIDER and the STORIX_<PROVIDER>_* variables (or a .env file) through pydantic-settings. So the simplest configuration is environment variables plus a bare get_storage().

From the environment

STORIX_PROVIDER=azure
STORIX_AZURE_CONTAINER=raw
STORIX_AZURE_ACCOUNT_NAME=myaccount
STORIX_AZURE_CREDENTIAL=...
from storix import get_storage

fs = get_storage()   # provider and credentials come from the environment

From your app's settings

To keep storage config next to the rest of your configuration, wrap it in your own BaseSettings and pass overrides, which win over the environment:

"""Configure storix from settings.

get_storage is already settings-driven: it reads STORIX_PROVIDER and the
STORIX_<PROVIDER>_* variables (or a .env file) through pydantic-settings, so the
zero-code path is environment variables. To keep storage config next to the rest
of your app config, wrap it in your own BaseSettings and pass overrides, which
win over the environment.
"""

from __future__ import annotations

from pydantic_settings import BaseSettings, SettingsConfigDict

from storix import Storix, get_storage


def from_env() -> Storix:
    # Set STORIX_PROVIDER=azure, STORIX_AZURE_CONTAINER=..., etc. (or a .env
    # file), and get_storage picks them up with no code.
    return get_storage()


class Settings(BaseSettings):
    """Storage config kept alongside the rest of the app's settings."""

    model_config = SettingsConfigDict(env_prefix='APP_', env_file='.env')

    storage_base: str = '~/app-data'


def from_settings() -> Storix:
    settings = Settings()
    # Overrides beat the environment; each key mirrors the backend's kwarg.
    return get_storage('local', base=settings.storage_base)

Overrides map one-to-one onto a backend's constructor keywords, so base= is a LocalBackend option, container= an AzureBackend option, and so on.