Giter Club home page Giter Club logo

atomik's Introduction

๐Ÿš€ Atomik

Atomik provides you a python-friendly way to manage writing new file and folders in an atomic way. The main way to use the library is with to use the file and folder context manager. They will provide an easy interface to make sure the destination file/folder remain consistent.

This means you can be sure that you will not leave a file half written or a folder with half the files you wanted to write into in case of failure. When overwriting you can be sure that the data will be either the previous or the next version.

๐Ÿ“š Example

File

This will ensure either all the data is correctly written to file or none of it

with atomik.file("./result.json") as f:
    print(stream, file=f)

Folder

with atomik.folder("./result_folder") as dir:
    with open(Path(dir, "result_1.json") as f:
        print(result_1, file=f)
    with open(Path(dir, "result_2.json") as f:
        print(result_2, file=f)

๐Ÿ” Safe default

By default, atomik will not overwrite files/folders (but it's configurable)

๐Ÿค“ How ?

Atomik uses the new renameat2 syscall to allow to rename file in an atomic way. The syscall doesn't allow to overwrite a non-empty folder when renaming. This is achieved using the exchange flag to swap the two folder and then the source folder is cleaned. This may leave the src folder in case of interruption/issue when deleting but the destination folder will still be written in an atomic way.

Limitations

The rename syscall only work if the source and destination are on the same filesystem

Acknowledgement

This library's main goal is to provide a simple interface to rename file in a safe and simple way, without having to dive deep into OS specific documentation and limitations behind it. If you want to use the syscall directly I recommend these two libraries which helped the development of Atomik a lot:

atomik's People

Contributors

halbow avatar

Watchers

 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.