# Multi Filesystem¶

A MultiFS is a filesystem composed of a sequence of other filesystems, where the directory structure of each overlays the previous filesystem in the sequence.

One use for such a filesystem would be to selectively override a set of files, to customize behavior. For example, to create a filesystem that could be used to theme a web application. We start with the following directories:

-- templates
|-- snippets
|   -- panel.html
|-- index.html
|-- profile.html
-- base.html

-- theme
|-- snippets
|   |-- widget.html
|   -- extra.html
|-- index.html
-- theme.html

And we want to create a single filesystem that will load a file from templates/ only if it isn’t found in theme/. Here’s how we could do that:

from fs.osfs import OSFS
from fs.multifs import MultiFS

theme_fs = MultiFS()

Now we have a theme_fs filesystem that presents a single view of both directories:

|-- snippets
|   |-- panel.html
|   |-- widget.html
|   -- extra.html
|-- index.html
|-- profile.html
|-- base.html
-- theme.html
class fs.multifs.MultiFS(auto_close=True)[source]

A filesystem that delegates to a sequence of other filesystems.

Operations on the MultiFS will try each ‘child’ filesystem in order, until it succeeds. In effect, creating a filesystem that combines the files and dirs of its children.

Add a filesystem to the MultiFS.

Parameters: name (str) – A unique name to refer to the filesystem being added. fs (FS or str) – The filesystem (instance or URL) to add. write (bool) – If this value is True, then the fs will be used as the writeable FS (defaults to False). priority (int) – An integer that denotes the priority of the filesystem being added. Filesystems will be searched in descending priority order and then by the reverse order they were added. So by default, the most recently added filesystem will be looked at first.
get_fs(name)[source]

Get a filesystem from its name.

Parameters: name (str) – The name of a filesystem previously added. the filesystem added as name previously. FS KeyError – If no filesystem with given name could be found.
iterate_fs()[source]

Get iterator that returns (name, fs) in priority order.

which(path, mode=u'r')[source]

Get a tuple of (name, fs) that the given path would map to.

Parameters: path (str) – A path on the filesystem. mode (str) – An io.open mode.