Source: dvc/fs/dvc.py:82-754
Description
DVCFileSystem provides a unified file system interface to access both DVC-tracked and Git-tracked files in a repository. It implements the fsspec protocol, making it compatible with many data science libraries like pandas, PyTorch, and TensorFlow.
This is a lower-level API compared to dvc.api.open() and dvc.api.read(), offering more control and better performance when working with multiple files from the same repository.
DVCFileSystem is also available as dvc.api.DVCFileSystem for convenience.Signature
Parameters
Union[Repo, os.PathLike, str, None]
default:"None"
A URL, path to a DVC/Git repository, or a
Repo instance.- Defaults to the current working directory DVC project
- Can be a local path or remote URL
- Both HTTP and SSH protocols are supported
str
default:"None"
Any Git revision such as a branch name, tag name, commit hash, or DVC experiment name.
- Defaults to the default branch for remote repos
- For local repos without
rev, uses the working directory - Ignored if
repois not a Git repository
bool
default:"False"
Whether to traverse into subrepos (nested DVC repositories).
dict
default:"None"
DVC config dictionary to be passed to the repository.
str
default:"None"
Name of the DVC remote to use.
dict
default:"None"
Remote configuration dictionary.
Methods
File Operations
Open a file for reading.
Download file(s) from the repository to local path.
Download a single file.
Directory Operations
List directory contents.
Walk through directory tree.
File Info
Get file or directory information.
Check if a path exists.
Check if path is a file.
Check if path is a directory.
Check if path is DVC-tracked.
Utilities
Get disk usage for a path.
Get current working directory.
Join path components.
Examples
Basic File Reading
List Directory Contents
Download Files
Walk Directory Tree
Check DVC Tracking Status
Use with Pandas
Use with NumPy
Multiple File Operations
Compare File Sizes
Get Directory Size
Filter DVC-Tracked Files
Access Private Repository
Use Cases
Batch Processing
Process multiple files from a repository efficiently.
Library Integration
Use with pandas, PyTorch, TensorFlow via fsspec protocol.
Directory Operations
List, walk, and analyze directory structures.
Performance
Better performance than
open()/read() for multiple operations.fsspec Compatibility
DVCFileSystem implements the fsspec protocol, making it compatible with many libraries:
Pandas
PyTorch
Dask
Comparison with dvc.api Functions
Best Practices
Reuse filesystem instances
Reuse filesystem instances
Create one instance and reuse it for multiple operations:
Use appropriate methods
Use appropriate methods
Choose the right method for your use case:
Close when done
Close when done
Close the filesystem when finished (or use context manager if available):
Leverage fsspec compatibility
Leverage fsspec compatibility
Take advantage of fsspec protocol support in libraries:
Related Functions
open()
Simple file opening
read()
Simple file reading
get_url()
Get storage URL
Advanced Usage: See the fsspec documentation for more details on the file system protocol and advanced features.