-
Notifications
You must be signed in to change notification settings - Fork 376
pathlib.Path type #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(maybe my bias against pathlib keeps showing through)
I am not opposed in principle, but I don't immediately see how this would work. It sounds like a pain to implement? |
Agreed that it may be a pain to implement all of the FS-touching operations present in However, the API of |
Is this something you are proposing to take on? :) |
If anyone else thinks it would be valuable and it would make it through review, I may be able to find time! |
Let's see if other people chime in. pathlib has certainly been mentioned before in the issues. |
Hello! At Data Revenue we have crafted a drfs package that does more or less what you described. Example: from drfs import DRPath
dir_path = DRPath("s3://bucket/key")
file_path = dir_path / "file.txt"
with file_path.open("rb") as f:
f.read() Another example (presenting another functionality of the package) is here. It is an internal package and was opensourced just yesterday (actually because of this thread), so I realise that the documentation is not perfect and there are bugs here and there. The package will be probably refactored in the near future (possibly as you described - by integrating with fsspec), but maybe it can already be of use for you. :) |
I stumbled across this yesterday https://github.com/drivendataorg/cloudpathlib. Could be used as inspiration here |
Hurray for the extra functionality, @michcio1234 ! We would gladly see something like this included directly in fsspec, or indeed as a separate package. @raybellwaves , I will post an issue on that repo to see if they are interested in contributing - or as inspiration, as you say. |
@michcio1234 , also I'd note that your second example starts to look something like an intake catalog spec |
I would also love to have a import pathlib
my_path = pathlib.Path("s3://my-bucket/experiment-1") / "results.csv"
my_path returns:
When used with import fsspec
with fsspec.open(my_path, "w") as f:
f.write("my results") Locally a folder |
Ooops... Again, I'd be really happy for someone to contribute this, but it likely won't be me. |
This is something I've been thinking about and wanting too. The particular advantage is that it then allows you to use fsspec with (almost) any function that expects a pathlib.Path object. I think that it could be quite a simple class that acts as an adapter between the pathlib.Path API and the fsspec.AbstractFileSystem API. |
Agree. I use |
One more vote here, we have just started looking into this. One very simple way we tried is just to implement the |
Can you develop on fspath? |
My reading of |
import pathlib
p = pathlib.PurePath('s3://bucket-data/setup.py')
print(str(p), p.__fspath__())
One way would be to monkey-patch |
ok, sorry I wasn't clear, I just mean that supporting the path protocol (not the full pathlib.PurePath) help us a lot already. |
It looks like someone is building a lib for this: https://github.com/Quansight/universal_pathlib Friendly ping to @tonyfast and @andrewfulton9: would you consider contributing directly here instead of in an external library? @martindurant any thoughts on this? |
Sure! Since it needs no further dependencies, it might well be hosted within fsspec - but maybe it doesn't matter. I'd be happy to put something into fsspec's docs pointing to the examples of upath for those looking for Path support, if the package is to remain separate. As far as I can see, upath has only been up for six days, so we'll see how it goes. |
I think https://github.com/Quansight/universal_pathlib is pretty much the kind of adapter I had in mind. It looks like it's far too early to include in fsspec now, but I think it ought to be integrated when it's more mature. |
Even if it's an early project, it would make sense to add early in fsspec but I guess it depends on what the dev wants to do here. |
Let's wait for the quansight people to comment :) |
@martindurant , agreed. @hadim , if it were me, this early in a project, then I'd want to be able to iterate faster than a more established project like fsspec. |
Thanks for pinging me. I'm glad to see the interest in |
Do you think it's worth mentioning somewhere in the fsspec documentation yet? |
I think it is worth mentioning, maybe with the caveat that it's still in the early stage of development. So far my test suite covers most of the relevant |
What is the progress? @andrewfulton9 there is no supprt for huggingface file system 'hf' |
pathlib is great for interacting with paths on the local file system. It's expressive, terse, ergonomic, and typed. I'd love to use fsspec going forward, but don't want to give up the power and convenience of pathlib.
Could
AbstractFileSystem
s contain a factory method which produced a PurePath subclass with the correct separator, prefix etc.? This concrete class could also contain the methods implemented by pathlib.Path or it could just be passed back to the filesystem.The text was updated successfully, but these errors were encountered: