Skip to content

Commit 0589358

Browse files
authored
Merge pull request #753 from TomAugspurger/feature/doc-url_to_fs
Added fsspec.core.url_to_fs to public API
2 parents d952ace + 756caa3 commit 0589358

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/source/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Base Classes
4040
fsspec.core.OpenFiles
4141
fsspec.core.BaseCache
4242
fsspec.core.get_fs_token_paths
43+
fsspec.core.url_to_fs
4344
fsspec.dircache.DirCache
4445
fsspec.registry.ReadOnlyRegistry
4546
fsspec.registry.register_implementation
@@ -72,6 +73,8 @@ Base Classes
7273

7374
.. autofunction:: fsspec.core.get_fs_token_paths
7475

76+
.. autofunction:: fsspec.core.url_to_fs
77+
7578
.. autoclass:: fsspec.dircache.DirCache
7679
:members: __init__
7780

fsspec/core.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,25 @@ def _un_chain(path, kwargs):
352352

353353

354354
def url_to_fs(url, **kwargs):
355-
"""Turn fully-qualified and potentially chained URL into filesystem instance"""
355+
"""
356+
Turn fully-qualified and potentially chained URL into filesystem instance
357+
358+
Parameters
359+
----------
360+
url : str
361+
The fsspec-compatible URL
362+
**kwargs: dict
363+
Extra options that make sense to a particular storage connection, e.g.
364+
host, port, username, password, etc.
365+
366+
Returns
367+
-------
368+
filesystem : FileSystem
369+
The new filesystem discovered from ``url`` and created with
370+
``**kwargs``.
371+
urlpath : str
372+
The file-systems-specific URL for ``url``.
373+
"""
356374
chain = _un_chain(url, kwargs)
357375
if len(chain) > 1:
358376
inkwargs = {}

fsspec/tests/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,11 @@ def test_chained_fo():
323323
with of[0] as f:
324324
assert f.read() == b"test"
325325
assert "afile" in os.listdir(d3)
326+
327+
328+
def test_url_to_fs():
329+
url = "memory://a.txt"
330+
fs, url2 = fsspec.core.url_to_fs(url)
331+
332+
assert isinstance(fs, MemoryFileSystem)
333+
assert url2 == "/a.txt"

0 commit comments

Comments
 (0)