Skip to main content

Safe copy, move, and write on remote drives

Project description

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

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")

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

rename_after_writing-0.0.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

rename_after_writing-0.0.5-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file rename_after_writing-0.0.5.tar.gz.

File metadata

  • Download URL: rename_after_writing-0.0.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for rename_after_writing-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e423c4b3a5a241ad671c3e49393923321de22a274c464579da6c8dfe264d6583
MD5 5e711d7d1e2b3734c72a7e7a57eeb1ff
BLAKE2b-256 ab62de00e55b5550f52b07ab2801eb6fb6a8bf8d666884fc0b2bd412a677931a

See more details on using hashes here.

File details

Details for the file rename_after_writing-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for rename_after_writing-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fe2ac7a67f25cd2ebdaa6da430baa678fb1668579932aba6a1d3bf44870bce3e
MD5 365e15d1a28e87ecc99af4fb301c79f6
BLAKE2b-256 9442e15de43b9a9ae59fd33838b7db0a9b8dc12c7d8027af7c5a9b51aefc1859

See more details on using hashes here.

Supported by

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