Skip to main content

Atomik provides you a python-friendly way to manage writing new file and folders in an atomic way.

Project description

🚀 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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atomik-0.0.3rc1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atomik-0.0.3rc1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file atomik-0.0.3rc1.tar.gz.

File metadata

  • Download URL: atomik-0.0.3rc1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for atomik-0.0.3rc1.tar.gz
Algorithm Hash digest
SHA256 53dad91ecb8d0fcb22512a7134ef70c5993663a986eb6349496df188a336a112
MD5 13463f3758def82d0a4541448a9a39cf
BLAKE2b-256 7ca5978ad38755fc762e8cb3704def88a5855dea6e93206cfbfa143c196c777c

See more details on using hashes here.

File details

Details for the file atomik-0.0.3rc1-py3-none-any.whl.

File metadata

  • Download URL: atomik-0.0.3rc1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for atomik-0.0.3rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 abee8b36bc9331bb4d903389fca620617f3eb94878fd832433871b9ebcba3e45
MD5 48acf52a9f0ad4fe30bd34f1ed55fb45
BLAKE2b-256 f2e98f3239d10467febfa520ed6dab860112681a02b2bde79895c52d2c80e4f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page