Skip to main content

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

A python-library to help with the completeness of files when moving, copying and writing. Writing a file is not atomic. In the worst case the process writing the file dies while the file is not yet complete. Also in some network-file-systems, the destination of a move or copy might show up before it is complete. Incomplete files are a potential risk for the integrity of your data. In the best case your reading process crashes, but in the worst case the incompleteness goes unnoticed. This package reduces the risk of having incomplete files by making all writing operations write to a temporary file in the destination’s directory first before renaming it to its final destination. On most file-systems this final renamig is atomic.

Install

pip install rename_after_writing

Functions

Path

Writes to a temporary path and move it to your desired path on exit.

import rename_after_writing as rnw

with rnw.Path(path="my_file.txt") as tmp_path:
    with open(tmp_path, "wt") as f:
        for i in range(10):
            f.write(input())

Note, that while you write to the file (while you provide input()) the file is written into a temporary file named path + . + uuid(). After writing, on exit of the contextmanager, the temporary file is moved to path.

open

Just like python’s built in open() but when writing (mode=w) everything is writen to a temporary file in the destination’s directory before the temporary file is renamed to the final destination.

import rename_after_writing as rnw

with rnw.open("my_file.txt", "wt") as f:
    for i in range(10):
        f.write(input())

copy

Copies the file first to a temporary file in the destinations directory before moving it to its final path.

import rename_after_writing as rnw

rnw.copy(src="machine/with/src", dst="other/machine/in/network/dst")

move

Some implementations of network-file-systems might raise an OSError with errno.EXDEV when an os.rename() is going across the boundary of a physical drive. In this case, this package’s copy is used to copy the file beore unlinking the source-file.

import rename_after_writing as rnw

rnw.move(src="machine/with/src", dst="other/machine/in/network/dst")

Metadata

Release files for rename-after-writing 0.0.13

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

Source distribution (sdist)

Source distribution for rename-after-writing 0.0.13
File Size Uploaded
rename_after_writing-0.0.13.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rename-after-writing 0.0.13
File Interpreter ABI Platform
rename_after_writing-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / rename_after_writing-0.0.13.tar.gz

Download URL rename_after_writing-0.0.13.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b054276d62f8790332bd89dea8f7dea0ceb04c8ba74c969336eabcc46ba0f22f
BLAKE2b-256 checksum
How to use checksums
76a1cc3226d9e17249568e63580c6593219399167156768ded0cd7ec9c774215
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release files / rename_after_writing-0.0.13-py3-none-any.whl

Download URL rename_after_writing-0.0.13-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c19379f11d12af512cb9ab0dd5909f7759381dda494b755934acda298af0a7dd
BLAKE2b-256 checksum
How to use checksums
8717b29f485605e32349e0dcaa55f4ed5d26c55a9a9112bde31161793e3189eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

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