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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17e8c07af947763c13c1440d444ad6acf475ce24fd8b20947fae01cf20bfb0c2
|
|
| MD5 |
07f5f855c4710d8604d70fdda0bd93f1
|
|
| BLAKE2b-256 |
4be322cb9bb074b343a45a0887c1f5a80321228931c447c1c605928688e755d5
|
Provenance
The following attestation bundles were made for safefile-0.1.0.tar.gz:
Publisher:
publish.yml on AbirHasanSupta/safefile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safefile-0.1.0.tar.gz -
Subject digest:
17e8c07af947763c13c1440d444ad6acf475ce24fd8b20947fae01cf20bfb0c2 - Sigstore transparency entry: 1667381699
- Sigstore integration time:
-
Permalink:
AbirHasanSupta/safefile@710fdcfaecb3e605a595280aaf50ef3f6f51d3ee -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AbirHasanSupta
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@710fdcfaecb3e605a595280aaf50ef3f6f51d3ee -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05c491ae1732898f1b705b4c96926cc5f4a8bead6c09d37790c36108c8b98b18
|
|
| MD5 |
aa2b006397a8453a4c0f3fc3133e53de
|
|
| BLAKE2b-256 |
46f093cf02777428ffe9a5de4ea7c8dd3dee289359efac098535c0f7076b53e5
|
Provenance
The following attestation bundles were made for safefile-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on AbirHasanSupta/safefile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safefile-0.1.0-py3-none-any.whl -
Subject digest:
05c491ae1732898f1b705b4c96926cc5f4a8bead6c09d37790c36108c8b98b18 - Sigstore transparency entry: 1667381785
- Sigstore integration time:
-
Permalink:
AbirHasanSupta/safefile@710fdcfaecb3e605a595280aaf50ef3f6f51d3ee -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AbirHasanSupta
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@710fdcfaecb3e605a595280aaf50ef3f6f51d3ee -
Trigger Event:
release
-
Statement type: