Skip to main content

Transactional file modifications – atomic, rollback on failure

Project description

safefile

Atomic, transactional file modifications – automatic rollback on failure.

Protect your files from being left corrupted or inconsistent if your script crashes.

Wrap file-changing code in a with transaction(...) block. If an exception occurs, all protected files are instantly restored to their previous state.

Installation

pip install safefile

Quick start

from safefile import transaction

# Basic protection (copy strategy)
with transaction("config.yaml", "data.csv"):
    update_config("config.yaml")
    update_data("data.csv")
    # If anything crashes, both files roll back.

How it works

  • On entering the block, a backup of each existing file is created (using a safe copy).
  • If the block completes without an exception, the backups are deleted – changes are committed.
  • If an exception is raised, the original files are restored from the backups; newly created files are removed.

License

MIT

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

safefile-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

safefile-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file safefile-0.1.0.tar.gz.

File metadata

  • Download URL: safefile-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safefile-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17e8c07af947763c13c1440d444ad6acf475ce24fd8b20947fae01cf20bfb0c2
MD5 07f5f855c4710d8604d70fdda0bd93f1
BLAKE2b-256 4be322cb9bb074b343a45a0887c1f5a80321228931c447c1c605928688e755d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for safefile-0.1.0.tar.gz:

Publisher: publish.yml on AbirHasanSupta/safefile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safefile-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safefile-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safefile-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05c491ae1732898f1b705b4c96926cc5f4a8bead6c09d37790c36108c8b98b18
MD5 aa2b006397a8453a4c0f3fc3133e53de
BLAKE2b-256 46f093cf02777428ffe9a5de4ea7c8dd3dee289359efac098535c0f7076b53e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for safefile-0.1.0-py3-none-any.whl:

Publisher: publish.yml on AbirHasanSupta/safefile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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