ACID transaction with common files
Project description
acidfile
This project was forked from https://github.com/nilp0inter/acidfile to fix issues with more recent versions of Python.
acidfile module provides the ACIDFile object. This object can be used as a regular file object but instead of write one copy of the data, it will write several copies to disk in an ACID manner.
This algorithm was explained by Elvis Pfützenreuter in his blog post Achieving ACID transactions with common files.
Latest stable version can be found on PyPI.
acidfile is compatible with python 2.7, 3.6 and up, and pypy
Installation
Latest version can be installed via pip
$ pip install --upgrade acidfile-optelgroup
Running the tests
Clone this repository and install the develop requirements.
$ git clone https://gitlab.com/optelgroup-public/acidfile.git
$ cd acidfile
$ pip install -r requirements/develop.txt
$ python setup.py develop
$ tox
Usage examples
Basic usage
>>> from acidfile import ACIDFile
>>> myfile = ACIDFile('/tmp/myfile.txt', 'w')
>>> myfile.write(b'Some important data.')
>>> myfile.close()
At the close invocation two copies will be written to disk: myfile.txt.0 and below myfile.txt.1. Each one will have an creation timestamp and a HMAC signature.
>>> myfile = ACIDFile('/tmp/myfile.txt', 'r')
>>> print myfile.read()
'Some important data.'
>>> myfile.close()
If any of the files is damaged due to turning off without proper shutdown or disk failure, manipulation, etc. It will be detected by the internal HMAC and the other’s file data would be used instead.
Context manager
ACIDFile can (and should) be used as a regular context manager:
>>> with ACIDFile('/tmp/myfile.txt', 'w') as myfile:
... myfile.write(b'Some important data.')
Number of copies
The number of inner copies of the data can be configured through the copies parameter.
Checksum Key
The key used for compute and check the internal HMAC signature can be setted by the key parameter.
It’s recommended to change that key in order to protect against fraud, making more difficult for a tamperer to put a fake file in place of the legitimate one.
News
1.2.2 (fork)
Fix missing parameter in hmac
Add support to Python 3.6 - 3.10
Rewrote the ci/cd pipeline using gitlab-ci
1.2.1
Using io.open in setup.py to read README and NEWS. This fix some problems installing the package.
Python 3.4 support.
1.2.0
Python 2.6 support.
Added Python 3.2 and pypy to tox tests.
Added flattr button :D
Fixed flake8 and pylint warnings.
1.1.0
Python 3 support.
Changed testing framework to behave because python 3 support.
Using tox for multiple python version testing.
1.0.0
First stable release.
Documentation.
0.0.1
Initial development.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file acidfile_optelgroup-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: acidfile_optelgroup-1.2.2-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 955acb1e1ea1458a7f55c7481327d4cf515776c9a7e4705a641cf298119ea998 |
|
MD5 | ccd13596d32e5e05d9b2be6d92db22c7 |
|
BLAKE2b-256 | b88836d52ad611a5704f0eada0f5a093b8a38819f1058164fc2454aea9210276 |