Skip to content

Backends

mountainash-transport ships four storage backends: local files, the S3 family (AWS S3, S3 Express One Zone, Cloudflare R2, MinIO and Backblaze B2), SFTP and HTTP(S). Each one is a class composed from per-capability mixins and registered for one or more provider types. The same facade call works on all of them as far as their protocols overlap. Where a store's own semantics differ (directory removal, copy limits, listing cost), the backend keeps the store's behaviour rather than emulating another's.

This page assumes the protocol and registry model from Architecture: protocols and dispatch, the connections from Leaf connections, and the access modes from Read access modes. Users who only need to know what a backend can do can read the support matrix and skip the rest.

Support matrix

The support matrix records which storage protocols each registered backend class implements. It is derived, not maintained by hand: the rows below come from running issubclass() against every class in get_registered_backends(), one column per protocol.

import mountainash_transport as mt
from mountainash_transport.storage.registry import get_registered_backends

protocols = [
    mt.StorageReadProtocol, mt.StorageWriteProtocol, mt.StorageEnumerateProtocol,
    mt.StorageDeleteProtocol, mt.StorageMetadataProtocol, mt.StorageCopyProtocol,
    mt.StorageMoveProtocol, mt.StorageDirectoryProtocol, mt.RangedReadProtocol,
    mt.StoragePresignProtocol,
]
for provider, cls in sorted(get_registered_backends().items()):
    have = [p.__name__.removeprefix("Storage").removesuffix("Protocol")
            for p in protocols if issubclass(cls, p)]
    print(f"{provider:10} {cls.__name__:22} {' '.join(have)}")

Output:

b2         S3StorageBackend       Read Write Enumerate Delete Metadata Copy RangedRead Presign
http       HTTPStorageBackend     Read Write Metadata RangedRead
local      LocalStorageBackend    Read Write Enumerate Delete Metadata Copy Move Directory
minio      S3StorageBackend       Read Write Enumerate Delete Metadata Copy RangedRead Presign
r2         S3StorageBackend       Read Write Enumerate Delete Metadata Copy RangedRead Presign
s3         S3StorageBackend       Read Write Enumerate Delete Metadata Copy RangedRead Presign
s3express  S3StorageBackend       Read Write Enumerate Delete Metadata Copy RangedRead Presign
sftp       SFTPStorageBackend     Read Write Enumerate Delete Metadata Move Directory RangedRead
Backend Provider types Extra Read Write Enumerate Delete Metadata Copy Move Directory RangedRead Presign
LocalStorageBackend local none yes yes yes yes yes yes yes yes no (native handle) no
S3StorageBackend s3, s3express, r2, minio, b2 [s3] yes yes yes yes yes yes no no yes yes
SFTPStorageBackend sftp [sftp] yes yes yes yes yes no yes yes yes no
HTTPStorageBackend http (also serves https://) [http] yes yes no no yes no no no yes no

The RangedRead column is satisfied structurally. No backend class inherits from RangedReadProtocol; the S3, SFTP and HTTP read mixins define open_ranged, and that method alone makes issubclass() true. Local has no open_ranged, and its random access comes from the native file handle instead (see Local).

tests/storage/protocols/test_backend_conformance.py asserts the same result for every column, for every registered provider type including b2, and checks the README's support table against it.

At runtime, StorageFacade.supports(protocol) answers the same question for one facade, as shown in Capabilities and supports(). The provider types with profiles but no backend (GCS, Azure, FTP, SMB, GitHub) do not appear here; a facade for one raises BackendNotImplementedError. The support matrix and known limits reference page collects this table with the documented limits.

Local

LocalStorageBackend (src/mountainash_transport/storage/backends/local/) works on the local filesystem with the standard library only, so it is the one backend available on a base install. It implements every protocol except RangedReadProtocol. It needs no connection: a facade built with a local storage profile gets a NullConnection, one built without a profile gets none, and the backend's connect() and disconnect() do nothing. Paths are plain filesystem paths or file:// URLs. The backend decodes a file:// URL on every operation, with or without a location policy; the URL must have an empty or localhost host, an absolute path and no user information, query or fragment, otherwise the call raises LocationNotAllowed with credentials removed from the message. A local storage profile's ROOT_PATH becomes the declared root for the location policy, as described in Confining local paths. Native OSErrors are translated at each call: FileNotFoundError to PathNotFoundError, PermissionError to PermissionDeniedError, other OSErrors to StorageError.

Native local handles

A random-access read on local storage returns a reader over the native file object from open(path, "rb"). The facade does not wrap it in a ranged reader or an extra buffer, so the handle keeps whatever methods the native file has, including seek, tell and fileno. OS errors raised later by those methods are translated in the same way as errors at open time.

import os, tempfile
from mountainash_transport import PathNotFoundError, RangedReadProtocol, StorageFacade

root = tempfile.mkdtemp()
with StorageFacade.for_local() as local:
    path = os.path.join(root, "data", "a.bin")
    local.write(path, b"0123456789")                 # creates data/ by default
    print(local.supports(RangedReadProtocol))         # -> False

    with local.read_stream(path, access="random") as fh:
        print(fh.seekable(), fh.fileno() > 0)        # native handle methods
        fh.seek(-3, os.SEEK_END)
        print(fh.read())                              # -> b'789'

    local.rmdir(os.path.join(root, "data"), recursive=True)  # removes the file too
    print(os.path.exists(path))                       # -> False

    try:
        local.read(path)
    except PathNotFoundError as exc:
        print(type(exc).__name__, "<-", type(exc.__cause__).__name__)

Output:

False
True True
b'789'
False
PathNotFoundError <- FileNotFoundError

A RangePolicy has no effect on local reads, because there is no range cache to tune.

S3 family

S3StorageBackend (src/mountainash_transport/storage/backends/s3/) wraps a boto3 client supplied by S3Connection. It implements read, write, enumerate, delete, metadata, copy and ranged read. Object stores have no directories, so it does not implement StorageDirectoryProtocol, and create_parents is accepted and ignored on writes. Paths are s3://bucket/key or bucket/key.

Each operation maps to one boto3 call or paginator. write uses put_object; write_stream uses upload_fileobj, which switches to multipart upload for large streams. Sequential reads return the get_object body as a forward-only stream. Ranged reads issue a head_object for the size and ETag, then one get_object with a Range header per cache miss, sending IfMatch with the strong ETag so that a change to the object raises ObjectChangedError instead of mixing two versions.

The example runs against a local S3-compatible endpoint. The server bootstrapping lines are omitted; endpoint is its URL and the bucket reports already exists.

from mountainash_auth_client import IAMAuthProfile
from mountainash_transport import PathNotFoundError, RangedReadProtocol, StorageFacade
from mountainash_transport.settings.storage.profiles import S3StorageProfile

profile = S3StorageProfile(FLAVOR="minio", ENDPOINT_URL=endpoint, BUCKET="reports", REGION="us-east-1")
auth = IAMAuthProfile(ACCESS_KEY_ID="x", SECRET_ACCESS_KEY="y")

with StorageFacade.from_path("s3://reports/", profile, auth_profile=auth) as s3:
    for name in ("a.csv", "b.csv", "c.csv"):
        s3.write(f"s3://reports/daily/{name}", b"0123456789")

    print(s3.supports(RangedReadProtocol))                 # -> True
    with s3.read_stream("s3://reports/daily/a.csv", access="random") as fh:
        fh.seek(-3, 2)
        print(fh.read())                                   # -> b'789'

    result = s3.list_objects("s3://reports/daily/", max_results=2)
    print([e.name for e in result.objects])

    s3.copy("s3://reports/daily/a.csv", "s3://reports/archive/a.csv")
    print(s3.exists("s3://reports/archive/a.csv"))         # -> True

    try:
        s3.read("s3://reports/missing.csv")
    except PathNotFoundError as exc:
        print(type(exc).__name__, exc, "<- cause:", exc.__cause__)

Output:

True
b'789'
['a.csv', 'b.csv']
True
PathNotFoundError s3://reports/missing.csv <- cause: None

The credentials come from an IAMAuthProfile owned by mountainash-auth-client, not from the storage profile; see Credentials come from auth-client.

One class, five provider types

S3StorageBackend is registered with five stacked @register_storage_backend decorators, for S3, S3EXPRESS, R2, MINIO and B2. The registry therefore returns the same class for s3://, s3express://, r2://, minio:// and b2:// paths, as the support matrix output shows. The differences between the services (endpoint URL, use_ssl default, region_name="auto" for R2, addressing style) are settled by the storage profile's FLAVOR field (aws, express, r2, minio or b2) and applied by S3Connection when it builds the boto3 client, as described in Provider profiles. The backend code never branches on the flavour. The names R2StorageBackend, S3ExpressStorageBackend, MinIOStorageBackend and B2StorageBackend remain importable from the backend package as aliases of S3StorageBackend.

SFTP

SFTPStorageBackend (src/mountainash_transport/storage/backends/sftp/) uses a paramiko SFTPClient from an SFTPConnection, which wraps an SSHConnection (see Leaf connections). It implements read, write, enumerate, delete, metadata, directory and ranged read. It does not implement StorageCopyProtocol, because SFTP version 3 has no server-side copy; copy_between moves data through the client instead. Paths are remote paths, or sftp://host[:port]/path URLs whose host and port must match the connected profile's HOST and PORT, otherwise the call raises LocationNotAllowed.

Sequential reads pull from the remote file on demand without prefetching. Ranged reads open one remote handle, read its size from stat, and serve each range with seek and read on that handle; there is no version pinning, so a file changed during a random read is not detected. Enumeration accepts only None or "/" as the delimiter. The SFTP tests replace the paramiko client with in-process fakes (tests/storage/backends/test_sftp.py) or with a fake whose calls act on a temporary directory (tests/storage/backends/test_directory_semantics.py); this page has no SFTP example because it needs a running SFTP server.

HTTP

HTTPStorageBackend (src/mountainash_transport/storage/backends/http/) sends every request through the HttpRequestEngine described in Making requests, so the engine's retry, timeout, redirect and safe-display policy and its auth strategy apply to storage calls too. Errors show the URL as scheme://host:port/path only, and the HTTP stat entry's path has userinfo removed but keeps query and fragment (see what HTTP errors show). It implements read (GET), write (PUT), metadata (HEAD) and ranged read. It is the only backend that accepts an auth_strategy, which carries the managed OAuth2 token flow, and the only one that receives the facade's location check per request, so redirects are checked against the policy as well.

Ranged reads probe the server with Range: bytes=0-0 instead of relying on HEAD or Accept-Ranges. A server that answers 200 instead of 206, or returns an encoded (for example gzip) representation, raises RangeNotSupportedError. Python's built-in http.server does not honour Range, which makes the refusal easy to see. The server bootstrapping lines are omitted; base is its URL.

from mountainash_transport import (
    RangeNotSupportedError, StorageEnumerateProtocol, StorageFacade,
)

url = f"{base}/report.csv"
with StorageFacade.from_path(url) as web:
    print(web.read(url))
    print(web.get_size(url))
    print(web.supports(StorageEnumerateProtocol))     # -> False
    try:
        web.read_stream(url, access="random")
    except RangeNotSupportedError as exc:
        print(type(exc).__name__, exc)

Output:

b'id,value\n1,42\n'
14
False
RangeNotSupportedError Expected 206, received 200

With no storage profile, the facade creates a default HTTPStorageProfile and its connection, so a bare URL is enough. Range probes send Accept-Encoding: identity and pin later ranges to a strong ETag with If-Match when the server supplies one.

Read plumbing

The facade returns two kinds of remote read stream. Sequential reads use forward-only adapters over the SDK's native stream. Random reads use RangedReader over the backend's RangedSource. Both are defined in private modules under src/mountainash_transport/_core/; callers see only a binary file object. The user-facing choice between them is in Choosing an access mode.

RangedReader

RangedReader (_core/ranged_io.py) is an io.RawIOBase over a RangedSource. It is seekable, and seeking only moves a position: no network request happens until read(). Reads go through an fsspec cache chosen by the RangePolicy (readahead, blockcache, bytes or none, with block_size and, for blockcache, max_blocks), which calls the source's fetch(start, end) for the bytes it lacks. A fetch that returns fewer bytes than requested raises StorageError. Closing the reader calls the source's on_close, which is how the SFTP backend closes its remote handle. Tuning is described in Range tuning.

Note

RangedReader reads through fsspec's cache classes using their internal _fetch method rather than a documented fsspec API. An fsspec release that changes that method would affect random reads on S3, SFTP and HTTP. The [http] extra constrains fsspec to >=2026.6.0,<2027. See the support matrix and known limits.

Sequential stream adapters

ForwardOnlyReader and IterBytesReader (_core/sequential_io.py) adapt a native source into an io.RawIOBase that the backends wrap in io.BufferedReader. ForwardOnlyReader takes a sized read callable and a close callable; S3 passes the get_object body's methods and SFTP the remote file handle's. IterBytesReader takes an iterator of chunks, which the HTTP backend uses for httpx streaming responses, and holds at most one incoming chunk. Both translate errors raised during read or close with the backend's error mapping, so a failure partway through a stream surfaces as a StorageError subclass with the native exception as its cause. The adapters themselves do not read ahead; the io.BufferedReader around them reads at most one buffer (8 KiB, io.DEFAULT_BUFFER_SIZE, by default) ahead of the caller.

Where backends differ

The protocols fix method names and error types. Some behaviour is left to the store, and the backends keep the store's semantics rather than emulating one another.

SFTP stream writes

The SFTP backend's write_from_stream uploads with paramiko's putfo, which copies the source in 32 KiB chunks, so write_stream, write with a transform pipeline and copy_between into SFTP use bounded memory. As on every backend, the caller's stream is left open.

S3 copy switches to multipart above 4 GiB

copy() on the S3 backend uses boto3's managed copy with a 4 GiB multipart threshold and 256 MiB parts. Below the threshold it is one CopyObject request; above it, CreateMultipartUpload, one UploadPartCopy per part and CompleteMultipartUpload, preserving the source's content type and metadata. Every copy first issues a HeadObject on the source to learn its size. The threshold is below each provider's single-request limit: 5 GB for Amazon S3 and S3 Express, 5 GB for Backblaze B2 standard files, 5 GiB less 5 MiB for Cloudflare R2; MinIO documents none. A multipart copy's ETag has a -<parts> suffix, unlike a single-request copy.

S3 listing with a limit

list_objects(..., max_results=n) on S3 asks for pages of at most n keys and stops fetching once it has n entries (objects first, then common prefixes), so a small limit costs one request. max_results=0 makes no request.

Other differences follow from the stores themselves. Deleting a missing local or SFTP file raises PathNotFoundError; deleting a missing S3 key succeeds. Ranged reads are pinned to an ETag on S3 and HTTP but not on SFTP. The create_parents option on writes applies to local and SFTP only.

Retries

Every remote backend retries transient failures, each in the way its SDK allows, under one RetryPolicy (src/mountainash_transport/_core/retry.py) configured by the storage profile's RETRY_* fields:

Backend Who retries Transient failures Profile fields Default
HTTP HttpRequestEngine retryable statuses (429, 500, 502, 503, 504), connection and timeout errors RETRY_MAX_ATTEMPTS, RETRY_BACKOFF_BASE, RETRY_BACKOFF_MAX 3 attempts, 1 s doubling to 60 s, jittered
SFTP ExecutorRetry, reconnecting the SSH session before each retry a lost session (StorageConnectionError) or a failed reconnect same three same
S3 family botocore, inside each request botocore's standard mode: throttling, 5xx, connection errors RETRY_MAX_ATTEMPTS (botocore owns the backoff) botocore's own settings: AWS_MAX_ATTEMPTS, AWS_RETRY_MODE, ~/.aws/config, else 5 attempts
Local nothing — — —

RETRY_MAX_ATTEMPTS=1 turns retry off. Errors that describe the path or the caller, such as PathNotFoundError, PermissionDeniedError and AuthenticationError, are never retried. Which operations retry:

Operation Retried
read, exists, get_size, metadata, list_objects, list_dir Yes
read_stream Only opening the stream; bytes already returned cannot be taken back. HTTP and S3 random-access reads retry each range; SFTP ones do not, because the file handle dies with the session
write (bytes) Yes
write_stream, copy_between into the store Only when the source is seekable, sent again from the position it started at (the HTTP body rule)
delete, mkdir, rmdir, move Yes
copy (S3) Yes, by botocore

An SFTP delete or move whose reply is lost with the session has already happened, so its retry finds the source gone and raises PathNotFoundError. A reconnect that SSH rejects, for a password or host key, is retried like a network failure until the attempts run out, because the connection layer does not keep paramiko's reason.

Backend error mapping

Each backend package has a private _helpers.py with a _mapped(path) context manager that its mixins place around every native call. It turns the SDK's exception into a StorageError subclass whose message is the display location alone for not-found, authentication and permission errors, and {display location}: {category} ({detail}) for the others. The detail is [Errno N] strerror when the native exception has an errno, and its class name otherwise. The native exception is not chained, so its text cannot leak a credential. The examples above show FileNotFoundError becoming PathNotFoundError on local storage and botocore's NoSuchKey doing the same on S3.

Native condition Local S3 (botocore) SFTP (paramiko) HTTP (engine)
Missing FileNotFoundError NoSuchKey, NoSuchBucket, 404 ENOENT HttpNotFoundError
Bad or expired credentials n/a InvalidAccessKeyId, ExpiredToken, 401 and others paramiko authentication failure HttpAuthenticationError
Access denied PermissionError AccessDenied, 403 EACCES, EPERM HttpForbiddenError
Network or timeout ConnectionError, TimeoutError botocore connection errors, RequestTimeout SSH and socket errors connection and timeout errors
Object changed n/a PreconditionFailed, 412 n/a 412

These map to PathNotFoundError, AuthenticationError, PermissionDeniedError, StorageConnectionError and ObjectChangedError in that row order; anything else from the SDK becomes a plain StorageError. Errors that describe the caller's input (botocore parameter validation, invalid URLs, the caller's own stream failing) are not translated. The HTTP mapping shows URLs as scheme://host:port/path. The exception hierarchy itself is described in Errors.