Skip to main content

English description follows Japanese.

atomic-save

概要

  • atomic-save は、ファイルを 破損させない安全な保存 を実現する Python の小型ツールです。
  • 保存途中にプログラムが落ちても、ファイルは 完全に書き込まれた状態 か 保存前の状態 のどちらかになります。

使い方の例

import atomic_save

# 文字列を atomic に保存
atomic_save["./testfile.txt"] = "hello!"

# バイト列を atomic に保存
atomic_save["./testfile.txt"] = b"hello!"

動作原理

データはまず 一時ファイル に完全に書き込まれます。 その後、書き込みが正常終了した段階で、一時ファイルが元ファイルと atomic に置き換え られます。 これにより、途中まで書かれた壊れたファイルが残ることはありません。

  • 一時ファイル名の形式: <元ファイル名>.<6桁16進ランダム>.atomic_save_temp
  • 保存できる型: str(文字列), bytes(バイト列)
  • 元ファイルが存在しない場合も問題なく保存可能 途中で落ちても「元々ファイルがなかった状態」に戻ります。

保存後の読み込みは通常どおり open() で行ってください。 成功した保存結果は常に元のファイル名に収まります。


atomic-save

Overview

  • atomic-save is a lightweight Python utility that guarantees corruption-free file writing.
  • Even if a crash occurs mid-save, the file will end up either fully written or completely unchanged.

Usage Example

import atomic_save

# Save text atomically
atomic_save["./testfile.txt"] = "hello!"

# Save bytes atomically
atomic_save["./testfile.txt"] = b"hello!"

How It Works

atomic-save writes all data into a temporary file first. After the write finishes successfully, it atomically replaces the original file with the completed temporary file. This design ensures no partially written file ever appears.

  • Temporary file format: <original_filename>.<6-digit hex random>.atomic_save_temp
  • Allowed value types: str, bytes
  • When the original file does not exist, saving works normally. If a crash occurs, the state cleanly falls back to “file did not exist.”

Reading the file requires no special API—just open the file normally. If the save succeeds, the completed data always appears under the original name.

Metadata

Release files for atomic-save 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atomic-save 0.0.0
File Size Uploaded Provenance
atomic_save-0.0.0.tar.gz 3.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for atomic-save 0.0.0
File Interpreter ABI Platform
atomic_save-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / atomic_save-0.0.0.tar.gz

Download URL atomic_save-0.0.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
844dea2de878c6a1be8f960c88050da874c7f16af372db1fc6c5971f69ee2de0
BLAKE2b-256 checksum
How to use checksums
623ce1e7d6f04d0d8298132ec2af3612773978976cbad6251e72ac1815b9c18f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release files / atomic_save-0.0.0-py3-none-any.whl

Download URL atomic_save-0.0.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49756ec9ca35b2a15908cbaed340ffcff5e57cdc7b7394b37d26d7de90700ed4
BLAKE2b-256 checksum
How to use checksums
09595a9eb86b9e8ff5dfdcc36afeefd2fba165d5877d2ea8220d17093cf01cbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Security for atomic-save 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page