A simple API to swap two files on a filesystem atomically
Project description
Atomic file swapping
Sadly, no, this is not a nuclear-powered utility to swap files. atomicswap
is a Python module that implements the swapping of two files on a filesystem
in a single operation that can't be broken up; either the entire operation
completes correctly or none of it completes. This prevents the filesystem
from being left in an inconsistent state and avoids certain race conditions.
The API is very simple; only a single swap() function is provided. The
function takes two file paths for the two files to be swapped. In the event
that either path is a relative path, you may also provide file descriptors
for directories that the relative paths should start from; if either is
missing then the path is relative to the current working directory. Paths
can be provided either as Python strings or pathlib paths.
Example
Swapping the files /etc/something/active and /etc/something/standby in
a single operation can be performed as follows:
from atomicswap import swap
...
swap("/etc/something/active", "/etc/something/standby")
Alternatively, if using Path objects, this could be implemented as:
from pathlib import Path
from atomicswap import swap
...
base_dir = Path("/etc/something")
swap(base_dir / "active", base_dir / "standby")
Platform support
Currently atomicswap supports Linux and macOS. A Windows version is a
possibility in the future.
License
atomicswap is released under the MIT license. See LICENSE.md for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file atomicswap-0.1.1.tar.gz.
File metadata
- Download URL: atomicswap-0.1.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9564ffb13ea53da730896a56013fcb55b42587a3f597255741e08165d7c91aa2
|
|
| MD5 |
f878676771ad318c45c80bfef2562dc6
|
|
| BLAKE2b-256 |
f8282c285771fc55bd44050bd51ac86d3493d82fb586cac77a0620dc4d798d53
|
File details
Details for the file atomicswap-0.1.1-py3-none-any.whl.
File metadata
- Download URL: atomicswap-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d5c12bd1c126c0dfe22aa8b81ad6e5db0e393b76bfc83c73a32772bbd041c9a
|
|
| MD5 |
06caf85e06a4585a7e30ee207d1c7171
|
|
| BLAKE2b-256 |
6bf819d7f7e36d149dfa959efe6e7031772a583a2b586e5126f29fef7035e35c
|