Description
Currently the user must instantiate a filesystem object manually (and thus know the filesystem name) to do analogue of os.listdir(...)
.
It would be nice to have more methods like existing fsspec.open(...)
mimicking Python's core open(...)
. E.g. methods with similar invokation API as os.listdir(...)
, os.path.exists(...)
etc (for simplifying porting existing scripts)
E.g. to be able to write generic code for simple usecases like:
# set up environment variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION, AWS_ENDPOINT_URL
# python ls.py s3://mybucket/
import sys, fsspec
print(fsspec.listdir(sys.argv[1]))
My current crutch:
import sys, fsspec
path = sys.argv[1]
listdir = fsspec.filesystem(path.split('://')[0] if '://' in path else 'file').ls
# from os import listdir
print(listdir(path))
# python lsfsspec.py .
# python lsfsspec.py file://.
# python lsfsspec.py s3://mybucket/
A complementing idea could be creating fsspec.Path
- an analogue of pathlib.Path
object accepting arbitrary paths like s3://
or github://
which would instantiate/cache filesystem object automatically and use some global configuration like environment variables, and providing the methods which pathlib.Path
currently supports