Git Product home page Git Product logo

acidfile's Introduction

acidfile

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.

image

Latest PyPI version

acidfile is compatible with python 2.6, 2.7, 3.2, 3.3, 3.4 and pypy

Contribute:

Flattr this git repo

Installation

Latest version can be installed via pip

$ pip install --upgrade acidfile

Running the tests

Clone this repository and install the develop requirements.

$ git clone https://github.com/nilp0inter/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.

Note

If you want to read an acidfile, never pass the full path of the real file, instead use the file name that you use in the creation step.

✗ ACIDFile('/tmp/myfile.txt.0', 'r')
✗ ACIDFile('/tmp/myfile.txt.1', 'r')
✓ ACIDFile('/tmp/myfile.txt', 'r')

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.

acidfile's People

Contributors

nilp0inter avatar bruchar1 avatar movermeyer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.