Skip to main content

Drop-in replacement for open() with automatic file versioning

Project description

versionIO

PyPI version License: MIT

A drop-in replacement for Python's open() function that automatically versions your files.

Features

  • 🔄 Drop-in replacement for Python's built-in open()
  • 📦 Automatic backups before every write operation
  • 🗂️ Version history with timestamps
  • 🔧 Configurable retention policies (keep last N versions)
  • 🚀 Zero dependencies - uses only Python standard library
  • 🖥️ Cross-platform - Windows, macOS, Linux
  • 🔒 Thread-safe with file locking

Installation

pip install versionio

Quick Start

Drop-in Replacement

Simply replace Python's open() with versionIO's:

# Instead of:
# from builtins import open

# Use:
from versionio import open

# Your existing code works without changes!
with open('important_file.txt', 'w') as f:
    f.write('New content')  # Old version automatically backed up!

High-level Interface

from versionio import VersionedFile

vf = VersionedFile('config.json')

# Write new content (auto-versioned)
vf.write('{"setting": "new_value"}')

# List all versions
for version in vf.versions():
    print(f"{version.timestamp}: {version.size} bytes")

# Restore previous version
vf.restore(vf.versions()[0])

Retention Policy

Keep only the last N versions to save space:

from versionio import open, VersionPolicy

# Keep only last 5 versions
policy = VersionPolicy(max_versions=5)

with open('data.csv', 'w', policy=policy) as f:
    f.write('id,name,value\n1,example,100')

How It Works

versionIO automatically creates backups before modifying files:

myfile.txt                    # Current file
.versions/
└── myfile.txt/
    ├── 20240115_143022_001.txt   # Backup from Jan 15, 14:30:22
    ├── 20240115_151533_001.txt   # Backup from Jan 15, 15:15:33
    └── 20240116_091000_001.txt   # Backup from Jan 16, 09:10:00

Advanced Features

Disable Versioning

# Disable for specific files
with open('temp.txt', 'w', versioning=False) as f:
    f.write('No backup needed')

Custom Policies

from versionio import VersionPolicy

policy = VersionPolicy(
    max_versions=10,      # Keep last 10 versions
    compress=False,       # Don't compress (future feature)
    diff_based=False,     # Store full copies (future feature)
)

Use Cases

  • Configuration files - Track every change to your app's settings
  • Data files - Keep history of CSV, JSON, or other data files
  • Log files - Maintain append history with automatic rotation
  • Critical documents - Never lose important modifications
  • Development - Simple version control for single files

Contributing

Contributions are welcome! Please see our Contributing Guide for details.

License

Licensed under the MIT License.

Links

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

versionio-0.1.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

versionio-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: versionio-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for versionio-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3d4f627c4962a70720372eb30b70a1136c5c8cbbe434e64c656df789bf9ae46
MD5 7420524a6b2be740b9195ad884667995
BLAKE2b-256 cfa4a097cece2b3bd46f2da814b2894aa95c66e27f0675c21fe971303e70260d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: versionio-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for versionio-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5533de9c0d6bfe7b27a479134051afe98e396904bc6f2bdac684154e5e8941dd
MD5 2350938c9a9a468d5f0d1e266267e3a2
BLAKE2b-256 4e42c5850db9b58c107e43774e2ae53008b0c7a08eb5336ddf97afb8e15f7ac6

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