morefs: A Collection of fsspec-based Filesystems

0.2.2 · active · verified Sun Apr 12

morefs is a Python library offering a collection of self-contained filesystems built on top of `fsspec`. It currently provides `AsyncLocalFileSystem`, `DictFileSystem`, and `OverlayFileSystem` to extend `fsspec`'s capabilities for asynchronous local operations, in-memory dictionary-backed storage, and layered filesystem views, respectively. The library is actively maintained, with the current version being 0.2.2, and releases occur as needed to address compatibility or introduce new features.

Warnings

Install

Imports

Quickstart

Demonstrates the initialization and basic usage of `AsyncLocalFileSystem`, `DictFileSystem`, and `OverlayFileSystem`, including listing directories and reading file content.

from fsspec import filesystem
from morefs.asyn_local import AsyncLocalFileSystem
from morefs.dict import DictFileSystem
from morefs.overlay import OverlayFileSystem
import asyncio

# AsyncLocalFileSystem
async def run_asynclocal_example():
    fs = filesystem("asynclocal") # or AsyncLocalFileSystem()
    # Using AsyncLocalFileSystem requires an async context
    print(f"AsyncLocalFileSystem ls '/': {await fs.ls('/')}")

# DictFileSystem
dict_fs = DictFileSystem({"foo": b"bar", "baz/qux": b"quux"})
print(f"DictFileSystem ls '/': {dict_fs.ls('/')}")
print(f"DictFileSystem read 'foo': {dict_fs.read_bytes('foo')}")

# OverlayFileSystem
lower_fs = DictFileSystem({"foo": b"bar_lower", "common": b"lower_val"})
upper_fs = DictFileSystem({"baz": b"qux_upper", "common": b"upper_val"})
overlay_fs = OverlayFileSystem(lower_fs=lower_fs, upper_fs=upper_fs)
print(f"OverlayFileSystem ls '/': {overlay_fs.ls('/')}")
print(f"OverlayFileSystem read 'foo': {overlay_fs.read_bytes('foo')}")
print(f"OverlayFileSystem read 'baz': {overlay_fs.read_bytes('baz')}")
print(f"OverlayFileSystem read 'common' (upper overrides): {overlay_fs.read_bytes('common')}")

# Run the async example
asyncio.run(run_asynclocal_example())

view raw JSON →