Sync and Manage Files¶
This guide covers synchronizing files and directories between filesystems, plus
partition-aware file management. The sync and partition helpers live in
fsspeckit.common and require no extra.
For exact signatures, see fsspeckit.common.
Directory synchronization¶
sync_dir() compares the path listings of a source and destination directory
on two filesystems, copies source-only files from source to destination, and
deletes stale destination-only files. Files present in both locations are left
untouched, so in-place updates to a matching path are not re-copied. It
returns a summary of what changed.
sync_dir() derives the add and delete lists from the two directory listings,
then delegates to sync_files(). Paths are relative to each filesystem's
configured root, so a DirFileSystem automatically confines the operation.
File-level synchronization¶
When you already know which files to add and delete, call sync_files()
directly:
Copy modes¶
- server_side (default
Trueonsync_dir,Falseonsync_files): when both filesystems are the same remote store, copy objects server-side without downloading them. - parallel and n_jobs: when
parallel=True, copy and delete operations run concurrently withn_jobsworkers (defaults to all cores). - chunk_size: bytes read and written per chunk for client-side copies (default 8 MB).
When server_side=True but the two filesystems are not the same store, the
operation falls back to a client-side copy automatically.
Cross-cloud sync¶
Because each filesystem is configured independently, you can sync between
different providers. Build each filesystem with its options, then point
sync_dir() at them. Cloud options require their extra - see
Configure Cloud Storage and the
extras matrix.
Partition management¶
get_partitions_from_path() extracts partition key/value pairs from a path.
Pass partitioning="hive" for hive-style key=value directories; it returns a
list[tuple[str, str]]. Use it to filter or group files by partition before
syncing.
Combined with a directory listing, this lets you sync only specific partitions.
Wrap the result in dict() to look up a column by name:
Parallel custom operations¶
For arbitrary per-file work, run_parallel() runs a function over one or more
iterables concurrently using joblib. Iterable arguments are zipped; non-iterable
arguments are passed fixed to every call.
run_parallel relies on joblib, which ships as a core dependency.
Related documentation¶
- Work with Filesystems - filesystem creation and path confinement.
- Optimize Performance - parallelism and caching.
- Generated API: fsspeckit.common - signatures.