Writeable file object that atomically updates a file.
Python
Permalink
Failed to load latest commit information.
debian Initial debianization. Jul 10, 2012
.gitignore Start to ignore something. Jul 10, 2012
.travis.yml
LICENSE.rst Add MIT license. Sep 18, 2013
README.rst Version bump to 1.0. Gratipay experiment. Oct 15, 2014
atomicfile.py add docstring for encoding argument Oct 14, 2014
setup.py Version bump to 1.0. Gratipay experiment. Oct 15, 2014
tests.py add test for encoding Oct 14, 2014

README.rst

AtomicFile

https://travis-ci.org/sashka/atomicfile.png?branch=master

Writeable file object that atomically updates a file.

All writes will go to a temporary file. Call close() explicitly when you are done writing, and AtomicFile will rename the temporary copy to the original name, making the changes visible. If the object is destroyed without being closed, all your writes are discarded.

AtomicFile is friendly to with statement.

from atomicfile import AtomicFile

with AtomicFile("panic.txt", "w") as f:
    f.write(json.dumps(big_data_array_100MB, sort_keys=True, indent=4))

Install

To install AtomicFile, simply:

pip install atomicfile