Skip to content

Cross-platform atomic file writer for all-or-nothing operations.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Ravencentric/atomicwriter

Repository files navigation

atomicwriter

Tests Build PyPI - Types License

PyPI - Latest Version PyPI - Python Version PyPI - Implementation

atomicwriter provides the AtomicWriter class, which performs cross-platform atomic file writes to ensure "all-or-nothing" operations—if a write fails, the target file is left unchanged.

Table Of Contents

Usage

from pathlib import Path
from atomicwriter import AtomicWriter

destination = Path("alpha_trion.txt")  # or str

with AtomicWriter(destination) as writer:
    writer.write_text("What defines a Transformer is not the cog in his chest, ")
    writer.write_text("but the Spark that resides in their core.\n")
    assert destination.is_file() is False

assert destination.is_file()

Checkout the complete documentation here.

Installation

atomicwriter is available on PyPI, so you can simply use pip to install it.

pip install atomicwriter

Building from source

Building from source requires the Rust toolchain and Python 3.9+.

  • With uv:

    git clone https://github.com/Ravencentric/atomicwriter
    cd atomicwriter
    uv build
  • With pypa/build:

    git clone https://github.com/Ravencentric/atomicwriter
    cd atomicwriter
    python -m build

Acknowledgements

This project is essentially a thin wrapper around the excellent tempfile crate, which handles all the heavy lifting for atomic file operations.

It is also heavily inspired by the now-archived atomicwrites project and uses a similar API.

License

Licensed under either of:

at your option.

Contributing

Contributions are welcome! Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Cross-platform atomic file writer for all-or-nothing operations.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks