API Reference
dCacheFileSystem
- class dcachefs.dCacheFileSystem(*args, **kwargs)[source]
Bases:
AsyncFileSystemFile system interface for a dCache storage instance.
Inspired by the fsspec HTTPFileSystem implementation, specific methods interacts with the dCache system either via its API or via the WebDAV protocol.
- Parameters:
api_url – (str, optional) dCache API URL
webdav_url – (str, optional) WebDAV door URL
username – (str, optional) username for basic authentication
password – (str, optional) password for basic authentication
token – (str, optional) token for bearer-token authentication
client_kwargs – (dict, optional) keyword arguments passed on to aiohttp.ClientSession, see https://docs.aiohttp.org/en/stable/client_reference.html . For example, {‘auth’: aiohttp.BasicAuth(‘user’, ‘pass’)}
request_kwargs – (dict, optional) keyword arguments passed on to the request method of aiohttp.ClientSession (also see client_kwargs)
block_size – (int, optional) when creating a file-like object, this is the buffer size (in bytes) for reading and writing. when reading, this is also the size downloaded in one request. if 0, will default to raw requests file-like objects
asynchronous – (bool, optional) use in asynchronous mode
loop – (optional) if asynchronous, event loop where to run coroutines
batch_size – (int, optional) if asynchronous, number of coroutines to submit/wait on simultaneously
encoded – use encoded strings when formatting URLs
storage_options – (dict, optional) keyword arguments passed on to the super-class
- property api_url
dCache API URL.
- created(path)[source]
Date and time in which the path was created.
- Parameters:
path – (str) target path
- Returns:
(datetime.datetime) time of creation
- info(path, **kwargs)
Give details about a file or a directory.
- Parameters:
path – (str) target path
kwargs – (dict, optional) arguments passed on to requests
- Returns:
(dict) path metadata
- ls(path, detail=True, limit=None, **kwargs)
List path content.
- Parameters:
path – (str) target path (file or directory)
detail – (bool, optional) if True, return a list of dictionaries with the (children) path(s) info. If False, return a list of paths
limit – (int, optional) set the maximum number of children paths returned to this value
kwargs – (dict, optional) arguments passed on to requests
- Returns:
(list) if detail is True, list of dictionaries. List of strings otherwise
- modified(path)[source]
Date and time in which the path was last modified.
- Parameters:
path – (str) target path
- Returns:
(datetime.datetime) time of last modification
- mv(path1, path2, **kwargs)
Rename path1 to path2.
- Parameters:
path1 – (str) source path
path2 – (str) destination path
kwargs – (dict, optional) arguments passed on to requests
- open(path, mode='rb', **kwargs)[source]
Return a file-like object from the filesystem.
- Parameters:
path – (str) target file path
mode – (str, optional) choose between “r”, “rb”, “w”, and “wb”
kwargs – (dict, optional) keyword arguments passed on to the super-class
- Returns:
(dCacheFile or dCacheStreamFile) file-like object
- rm(path, recursive=False, **kwargs)
Remove file or directory tree.
- Parameters:
path – (str) target path
recursive – (bool, optional) if True, and the target path is a directory, remove all subdirectories and their files
kwargs – (dict, optional) arguments passed on to requests
- property webdav_url
WebDAV door URL.
dCacheFile
- class dcachefs.dcachefs.dCacheFile(fs, url, mode='rb', block_size=None, request_kwargs=None, asynchronous=False, session=None, loop=None, **kwargs)[source]
Bases:
HTTPFileA file-like object pointing to a target file on dCache.
Supports reading, with read-ahead of a pre-determined block-size, and writing, with the file content being first cached and then uploaded to upon file closure.
- Parameters:
fs – (dCacheFileSystem) file-system instance creating the file
url – (str) target file path
mode – (str, optional) choose between “r”, “rb”, “w”, and “wb”
block_size – (int, optional) The amount of read-ahead to do, in bytes. Default is 5MB, or the value configured for the FileSystem creating this file
request_kwargs – (dict, optional) arguments passed on to requests
asynchronous – (bool, optional) use in asynchronous mode
session – (aiohttp.ClientSession, optional) All calls will be made within this session, to avoid restarting connections
loop – (optional) if asynchronous, event loop where to run coroutines
kwargs – (dict, optional) arguments passed on to the super-class
- flush(force=False)[source]
Write buffered data to remote file.
Since byte-range writing is not supported, the file content is only written when force is True (i.e. when the file-like object is closed).
- Parameters:
force – (bool, optional) Force writing of the remote file. Disallows further writing to this file.
- write_chunked()
Write buffered data to remote file.
dCacheStreamFile
- class dcachefs.dcachefs.dCacheStreamFile(fs, url, mode='rb', request_kwargs=None, asynchronous=False, session=None, loop=None, **kwargs)[source]
Bases:
HTTPStreamFileA streaming file-like object pointing to a target file on dCache.
Supports reading and writing by opening request streams to the remote file.
- Parameters:
fs – (dCacheFileSystem) file-system instance creating the file
url – (str) target file path
mode – (str, optional) choose between “r”, “rb”, “w”, and “wb”
request_kwargs – (dict, optional) arguments passed on to requests
asynchronous – (bool, optional) use in asynchronous mode
session – (aiohttp.ClientSession, optional) All calls will be made within this session, to avoid restarting connections
loop – (optional) if asynchronous, event loop where to run coroutines
kwargs – (dict, optional) arguments passed on to the super-class