Shortcuts

mmengine.fileio.get_file_backend

mmengine.fileio.get_file_backend(uri=None, *, backend_args=None, enable_singleton=False)[source]

Return a file backend based on the prefix of uri or backend_args.

Parameters:
  • uri (str or Path) – Uri to be parsed that contains the file prefix.

  • backend_args (dict, optional) – Arguments to instantiate the corresponding backend. Defaults to None.

  • enable_singleton (bool) – Whether to enable the singleton pattern. If it is True, the backend created will be reused if the signature is same with the previous one. Defaults to False.

Returns:

Instantiated Backend object.

Return type:

BaseStorageBackend

Examples

>>> # get file backend based on the prefix of uri
>>> uri = 's3://path/of/your/file'
>>> backend = get_file_backend(uri)
>>> # get file backend based on the backend_args
>>> backend = get_file_backend(backend_args={'backend': 'petrel'})
>>> # backend name has a higher priority if 'backend' in backend_args
>>> backend = get_file_backend(uri, backend_args={'backend': 'petrel'})