API Reference
This page provides detailed API documentation for all public classes, functions, and constants in SyncEngine.
Core Classes
SyncEngine
- class SyncEngine(client, entries_manager_factory, output=None, state_manager=None, pause_controller=None, concurrency_limits=None, spinner_factory=None, progress_bar_factory=None)
Core sync engine that orchestrates file synchronization.
- Parameters:
client (StorageClientProtocol) – Storage API client
entries_manager_factory (Callable) – Factory function that creates FileEntriesManagerProtocol instances
output (OutputHandlerProtocol) – Output handler for displaying progress (optional)
state_manager (SyncStateManager) – State manager for tracking sync history (optional)
pause_controller (SyncPauseController) – Controller for pause/resume/cancel (optional)
concurrency_limits (ConcurrencyLimits) – Concurrency limits for transfers and operations (optional)
spinner_factory (SpinnerFactoryProtocol) – Factory for creating progress spinners (optional)
progress_bar_factory (ProgressBarFactoryProtocol) – Factory for creating progress bars (optional)
- sync_pairs(pairs: list[SyncPair]) list[dict[str, int]]
Execute synchronization for multiple sync pairs.
- download_folder(destination_path: str, local_path: Path, sync_progress_tracker: SyncProgressTracker | None = None, parallel: bool = False, use_rich_progress: bool = True) dict[str, int]
Download a folder from destination to local filesystem.
- Parameters:
destination_path (str) – Path in destination storage
local_path (Path) – Local path to download to
sync_progress_tracker (SyncProgressTracker) – Optional progress tracker for monitoring download progress (new in v0.2.0)
parallel (bool) – Whether to download files in parallel (default: False)
use_rich_progress (bool) – Whether to display Rich progress bar (default: True, automatically disabled when sync_progress_tracker is provided)
- Returns:
Dictionary with download statistics (downloads, errors, etc.)
- Return type:
Note
When
sync_progress_trackeris provided, the Rich progress bar is automatically disabled to avoid UI conflicts. The tracker will emit detailed download events:DOWNLOAD_BATCH_START,DOWNLOAD_FILE_START,DOWNLOAD_FILE_PROGRESS,DOWNLOAD_FILE_COMPLETE,DOWNLOAD_FILE_ERROR,DOWNLOAD_BATCH_COMPLETE.
SyncPair
- class SyncPair(source_root, destination_root, source_client, destination_client, mode=SyncMode.TWO_WAY, comparison_mode=ComparisonMode.HASH_THEN_MTIME, ignore_manager=None, conflict_resolution=ConflictResolution.NEWEST_WINS)
Represents a source-destination pair for synchronization.
- Parameters:
source_root (str) – Root path of source directory
destination_root (str) – Root path of destination directory
source_client (StorageClientProtocol) – Storage client for source
destination_client (StorageClientProtocol) – Storage client for destination
mode (SyncMode) – Synchronization mode (default: TWO_WAY)
comparison_mode (ComparisonMode) – File comparison mode (default: HASH_THEN_MTIME)
ignore_manager (IgnoreFileManager) – Ignore pattern manager (optional)
conflict_resolution (ConflictResolution) – Conflict resolution strategy (default: NEWEST_WINS)
- source_root
Root path of source directory.
- destination_root
Root path of destination directory.
- mode
Synchronization mode.
- comparison_mode
File comparison mode for determining if files are identical.
- ignore_manager
Ignore pattern manager.
Enums
SyncMode
- class SyncMode
Synchronization modes for different sync strategies.
- TWO_WAY
Bidirectional sync. Changes on either side are propagated to the other.
- SOURCE_TO_DESTINATION
One-way mirror from source to destination. Destination changes are overwritten.
- SOURCE_BACKUP
Upload-only backup. Never deletes from source.
- DESTINATION_TO_SOURCE
One-way mirror from destination to source. Source changes are overwritten.
- DESTINATION_BACKUP
Download-only backup. Never deletes from destination.
- classmethod from_string(value: str) SyncMode
Parse sync mode from string, supporting abbreviations.
- Parameters:
value (str) – Mode string (full name or abbreviation)
- Returns:
SyncMode enum value
- Return type:
- Raises:
ValueError – If mode string is not recognized
Supported abbreviations:
tw→ TWO_WAYstd→ SOURCE_TO_DESTINATIONsb→ SOURCE_BACKUPdts→ DESTINATION_TO_SOURCEdb→ DESTINATION_BACKUP
- property allows_upload
Check if this mode allows uploading files.
- property allows_download
Check if this mode allows downloading files.
- property allows_source_delete
Check if this mode allows deleting source files.
- property allows_destination_delete
Check if this mode allows deleting destination files.
- property is_bidirectional
Check if this mode syncs in both directions.
ComparisonMode
- class ComparisonMode
File comparison strategies for determining if files are identical.
- HASH_THEN_MTIME
Default balanced mode. Compares hash if available, falls back to mtime. Files considered identical if sizes equal AND (hashes equal OR hash unavailable).
- SIZE_ONLY
Size-only comparison. Ignores hash and mtime completely. Files considered identical if sizes equal.
Use when: * Hash is unavailable or unreliable (e.g., encrypted storage) * Mtime is unreliable (e.g., upload time vs original file time)
Behavior with TWO_WAY sync: * Files with different sizes → CONFLICT (cannot determine newer file) * One-way sync uses sync direction to determine which file wins
- HASH_ONLY
Strict hash-only comparison. Ignores size and mtime. Files considered identical only if hashes match. Raises error if hash unavailable.
Use when: * Strict content verification required * Mtime is completely unreliable
Behavior with TWO_WAY sync: * Files with different hashes → CONFLICT (cannot determine newer file) * One-way sync uses sync direction to determine which file wins
- MTIME_ONLY
Time-only comparison. Ignores size and hash. Files considered identical if mtimes match (±2 second tolerance).
Use when: * Performance critical (skips hash computation) * Timestamps are reliable * Large files where hashing is expensive
- SIZE_AND_MTIME
Balanced comparison without hash. Compares both size AND mtime. Files considered identical if size equal AND mtime equal (±2 second tolerance).
Use when: * Hash unavailable but mtime is reliable * Need more accuracy than SIZE_ONLY * Good balance of performance and reliability
SyncAction
- class SyncAction
Actions that can be taken for a file during sync.
- UPLOAD_NEW
Upload a new file to destination.
- UPLOAD_UPDATE
Upload changes to existing destination file.
- UPLOAD_RESTORE
Re-upload file that was deleted at destination.
- DOWNLOAD_NEW
Download a new file from destination.
- DOWNLOAD_UPDATE
Download changes to existing source file.
- DOWNLOAD_RESTORE
Re-download file that was deleted at source.
- DELETE_SOURCE
Delete file from source.
- DELETE_DESTINATION
Delete file from destination.
- NO_ACTION
File is already in sync, no action needed.
- CONFLICT
Manual resolution required.
State Management
SyncStateManager
- class SyncStateManager(state_dir: Path)
Manages persistent sync state across sync sessions.
- Parameters:
state_dir (Path) – Directory to store state files
- load_source_tree() SourceTree
Load previous source state.
- Returns:
Source tree from last sync
- Return type:
- load_destination_tree() DestinationTree
Load previous destination state.
- Returns:
Destination tree from last sync
- Return type:
- save_source_tree(tree: SourceTree) None
Save current source state.
- Parameters:
tree (SourceTree) – Source tree to save
- save_destination_tree(tree: DestinationTree) None
Save current destination state.
- Parameters:
tree (DestinationTree) – Destination tree to save
SourceTree
DestinationTree
Ignore Patterns
IgnoreFileManager
- class IgnoreFileManager(patterns: list[str] = None)
Manages gitignore-style ignore patterns.
- add_pattern(pattern: str) None
Add an ignore pattern.
- Parameters:
pattern (str) – Pattern to add (gitignore syntax)
- load_from_file(file_path: Path) None
Load patterns from a file.
- Parameters:
file_path (Path) – Path to ignore file
IgnoreRule
Concurrency
ConcurrencyLimits
SyncPauseController
- class SyncPauseController
Controller for pausing, resuming, and canceling sync operations.
Progress Tracking
SyncProgressTracker
- class SyncProgressTracker(callback: Callable[[SyncProgressEvent], None])
Tracks and reports sync progress.
- Parameters:
callback (Callable) – Callback function for progress events
- on_scan_complete(total: int) None
Called when file scanning completes.
- Parameters:
total (int) – Total files scanned
- on_sync_start(total_files: int) None
Called when sync operations start.
- Parameters:
total_files (int) – Total files to sync
- on_upload_progress(file_path: str, bytes_transferred: int, total_bytes: int) None
Called during file upload.
- on_upload_complete(file_path: str) None
Called when file upload completes.
- Parameters:
file_path (str) – Path of file uploaded
- on_download_progress(file_path: str, bytes_transferred: int, total_bytes: int) None
Called during file download.
- on_download_complete(file_path: str) None
Called when file download completes.
- Parameters:
file_path (str) – Path of file downloaded
- on_download_batch_start(directory: str, num_files: int, total_bytes: int) None
Called when batch download for a folder starts.
- on_download_file_start(file_path: str, file_size: int) None
Called when individual file download starts.
- on_download_file_progress(file_path: str, bytes_downloaded: int, total_bytes: int) None
Called during file download with progress updates.
- on_download_file_complete(file_path: str) None
Called when file download completes successfully.
- Parameters:
file_path (str) – Path of file downloaded
- on_download_batch_complete(directory: str, num_downloaded: int) None
Called when batch download completes.
SyncProgressEvent
- class SyncProgressEvent
Event types for progress callbacks.
Scan Events:
- SCAN_DIR_START
Directory scanning started.
- SCAN_DIR_COMPLETE
Directory scanning completed.
Upload Events:
- UPLOAD_BATCH_START
Batch upload for a folder started.
- UPLOAD_FILE_START
Individual file upload started.
- UPLOAD_FILE_PROGRESS
File upload progress update.
- UPLOAD_FILE_COMPLETE
File upload completed successfully.
- UPLOAD_FILE_ERROR
File upload failed.
- UPLOAD_BATCH_COMPLETE
Batch upload completed.
Download Events:
- DOWNLOAD_BATCH_START
Batch download for a folder started.
- DOWNLOAD_FILE_START
Individual file download started.
- DOWNLOAD_FILE_PROGRESS
File download progress update.
- DOWNLOAD_FILE_COMPLETE
File download completed successfully.
- DOWNLOAD_FILE_ERROR
File download failed.
- DOWNLOAD_BATCH_COMPLETE
Batch download completed.
SyncProgressInfo
- class SyncProgressInfo
Progress information object passed to callbacks.
- event
Event type (SyncProgressEvent enum value).
- file_path
File path (for file-specific events).
- directory
Directory path (for batch events).
- current_file_bytes
Bytes transferred for current file.
- current_file_total
Total bytes for current file.
- folder_bytes_uploaded
Bytes uploaded in current folder.
- folder_bytes_downloaded
Bytes downloaded in current folder.
- folder_bytes_total
Total bytes for current folder.
- folder_files_uploaded
Files uploaded in current folder.
- folder_files_downloaded
Files downloaded in current folder.
- total_bytes_uploaded
Total bytes uploaded across all operations.
- total_bytes_downloaded
Total bytes downloaded across all operations.
- total_files_uploaded
Total files uploaded across all operations.
- total_files_downloaded
Total files downloaded across all operations.
- error_message
Error message (for error events).
- stats
Sync statistics (for sync_complete event).
Configuration
SyncConfig
- class SyncConfig
Configuration for sync operations.
- chunk_size
Chunk size for uploads in bytes (default: 5MB).
- multipart_threshold
File size threshold for multipart uploads in bytes (default: 50MB).
- max_retries
Maximum number of retries for failed operations (default: 3).
- retry_delay
Delay between retries in seconds (default: 1.0).
- load_sync_pairs_from_json(file_path: Path) list[SyncPair]
Load sync pairs from a JSON configuration file.
- Parameters:
file_path (Path) – Path to JSON config file
- Returns:
List of configured sync pairs
- Return type:
- Raises:
SyncConfigError – If config file is invalid
Example JSON format:
{ "pairs": [ { "source_root": "/home/user/documents", "destination_root": "/backup/documents", "mode": "twoWay" } ] }
Constants
- DEFAULT_CHUNK_SIZE
Default chunk size for uploads (5MB).
- DEFAULT_MULTIPART_THRESHOLD
Default file size threshold for multipart uploads (50MB).
- DEFAULT_MAX_RETRIES
Default maximum number of retries (3).
- DEFAULT_RETRY_DELAY
Default delay between retries in seconds (1.0).
- DEFAULT_TRANSFERS_LIMIT
Default maximum concurrent transfers (5).
- DEFAULT_OPERATIONS_LIMIT
Default maximum concurrent operations (10).
- DEFAULT_BATCH_SIZE
Default batch size for operations (100).
- DEFAULT_IGNORE_FILE_NAME
Default ignore file name (“.syncignore”).
- DEFAULT_STATE_DIR_NAME
Default state directory name (“.sync_state”).
Exceptions
- exception SyncConfigError
Raised when sync configuration is invalid.
- exception SyncOperationError
Raised when a sync operation fails.
- exception StorageError
Raised when a storage operation fails.
Protocols
See Storage Protocols for detailed protocol documentation.
StorageClientProtocol- Interface for storage backendsFileEntryProtocol- Interface for file/folder metadataFileEntriesManagerProtocol- Interface for managing file collectionsOutputHandlerProtocol- Interface for output handlingSpinnerFactoryProtocol- Interface for progress spinnersProgressBarFactoryProtocol- Interface for progress bars
Next Steps
Examples - See complete usage examples
Storage Protocols - Learn about implementing storage backends
Core Concepts - Understand core concepts