Skip to main content

A robust file synchronization and backup library for Python

Project description

FileSync-Guardian

A robust file synchronization and backup library for Python with versioning, encryption, and smart delta transfers.

Features

  • 🔄 Smart Synchronization: Intelligently sync files between directories with efficient delta transfers
  • 📚 Versioning System: Keep historical versions of files with easy rollback
  • 🔒 Encryption Layer: Integrated file encryption for sensitive data
  • ⏱️ Progress Reporting: Real-time progress tracking with ETA and speed estimates
  • 🔍 Integrity Verification: Checksum validation ensures files transfer correctly
  • 🧰 Flexible Filters: Include/exclude patterns for precise control
  • 📊 Detailed Logging: Comprehensive logging of all operations

Installation

pip install filesync-guardian

Quick Start

Basic Synchronization

from filesync_guardian import SyncManager

# Initialize a SyncManager with source and target directories
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target"
)

# Start synchronization
sync_manager.start()

With Progress Reporting

from filesync_guardian import SyncManager

# Initialize the SyncManager
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target"
)

# Define progress callback
def on_progress(progress):
    print(f"Sync progress: {progress:.1f}%")

# Define completion callback
def on_complete():
    print("Synchronization completed successfully!")

# Define error callback
def on_error(exception):
    print(f"Synchronization failed: {exception}")

# Start synchronization with callbacks
sync_manager.start(
    on_progress=on_progress,
    on_complete=on_complete,
    on_error=on_error
)

With Encryption

from filesync_guardian import SyncManager

# Initialize with encryption enabled
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target",
    encryption=True,
    encryption_key="my-secure-password"  # Optional, auto-generated if not provided
)

# Start synchronization
sync_manager.start()

With File Versioning

from filesync_guardian import SyncManager

# Initialize with versioning enabled
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target",
    versioning=True,
    max_versions=10  # Keep up to 10 versions of each file
)

# Start synchronization
sync_manager.start()

# Restore a previous version
sync_manager.restore_version("/path/to/file.txt")

With Filters

from filesync_guardian import SyncManager

# Initialize with file filters
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target",
    filters=[
        "*.txt",           # Include all text files
        "-:*.tmp",         # Exclude temporary files
        "+:important/*.log" # Include log files in the important directory
    ]
)

# Start synchronization
sync_manager.start()

Advanced Usage

Bidirectional Synchronization

from filesync_guardian import SyncManager

# Initialize with bidirectional sync
sync_manager = SyncManager(
    source_path="/path/to/device1",
    target_path="/path/to/device2",
    bidirectional=True  # Changes from both sides are synchronized
)

# Start synchronization
sync_manager.start()

File Monitoring

from filesync_guardian.file_system.watcher import FileWatcher

# Create a file watcher
watcher = FileWatcher("/path/to/watch", recursive=True)

# Define event handlers
def on_file_created(path):
    print(f"File created: {path}")

def on_file_modified(path):
    print(f"File modified: {path}")

def on_file_deleted(path):
    print(f"File deleted: {path}")

# Set up callbacks
watcher.set_callbacks(
    on_created=on_file_created,
    on_modified=on_file_modified,
    on_deleted=on_file_deleted
)

# Start watching
watcher.start()

# ... Later when done ...
watcher.stop()

Checking Sync Status

from filesync_guardian import SyncManager

# Initialize the SyncManager
sync_manager = SyncManager(
    source_path="/path/to/source",
    target_path="/path/to/target"
)

# Start sync in the background
sync_manager.start()

# Check status
status = sync_manager.get_status()
print(f"Running: {status['is_running']}")
print(f"Progress: {status['progress']}%")
print(f"Current stage: {status['stage']}")
print(f"Last error: {status['last_error']}")

API Reference

SyncManager

The main class for managing file synchronization operations.

SyncManager(
    source_path,              # Source directory path
    target_path,              # Target directory path
    encryption=False,         # Whether to enable encryption
    encryption_key=None,      # Custom encryption key
    versioning=False,         # Whether to keep previous versions
    max_versions=5,           # Maximum versions to keep per file
    filters=None,             # List of include/exclude patterns
    bidirectional=False,      # Whether sync should be two-way
    verify_integrity=True,    # Whether to verify file integrity
    log_level=logging.INFO    # Logging level
)

Methods:

  • start(on_progress=None, on_complete=None, on_error=None): Start synchronization
  • stop(): Stop the current synchronization
  • get_status(): Get the current status
  • restore_version(file_path, version_id=None): Restore a previous version

FileWatcher

Monitors a directory for file changes.

FileWatcher(
    path,                   # Directory path to watch
    recursive=True,         # Whether to watch subdirectories
    polling_interval=1.0    # Seconds between checks
)

Methods:

  • start(): Start watching for changes
  • stop(): Stop watching
  • set_callbacks(on_created=None, on_modified=None, on_deleted=None): Set event handlers

Pattern

File pattern matcher for include/exclude rules.

Pattern(pattern_string)  # Pattern string with optional +/- prefix

Pattern Syntax:

  • *.txt: Include all .txt files
  • -:*.tmp: Exclude all .tmp files
  • +:dir/*.log: Include all .log files in dir/

Requirements

  • Python 3.7 or higher
  • cryptography >= 36.0.0

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filesync_guardian-0.1.1.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filesync_guardian-0.1.1-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file filesync_guardian-0.1.1.tar.gz.

File metadata

  • Download URL: filesync_guardian-0.1.1.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for filesync_guardian-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4c1b78b06e1bcbfb00a9b26b0ad728cfe3014aded8246b4f9ab051c033fada58
MD5 4de885d4fd21e1cbe19d4d52713b1a22
BLAKE2b-256 44d7d5020a5ca7c27c9a575566d4a6f479af6e0bf6277bb634c3d566a7578e9f

See more details on using hashes here.

File details

Details for the file filesync_guardian-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for filesync_guardian-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0843cce547c16a59aa7f6093a767cbf57106f2b580aa0599a6fd61e5c5772192
MD5 1ed37c44cf54232846780395597c5538
BLAKE2b-256 4e6718e74e2adc99714175f3164d1b938e9a916b418d9453cadd1a9cb7a3be4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page