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.
Release files for atomicswap 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| atomicswap-0.1.1.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| atomicswap-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / atomicswap-0.1.1.tar.gz
| Download URL | atomicswap-0.1.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9564ffb13ea53da730896a56013fcb55b42587a3f597255741e08165d7c91aa2
|
|
BLAKE2b-256 checksum How to use checksums |
f8282c285771fc55bd44050bd51ac86d3493d82fb586cac77a0620dc4d798d53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / atomicswap-0.1.1-py3-none-any.whl
| Download URL | atomicswap-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d5c12bd1c126c0dfe22aa8b81ad6e5db0e393b76bfc83c73a32772bbd041c9a
|
|
BLAKE2b-256 checksum How to use checksums |
6bf819d7f7e36d149dfa959efe6e7031772a583a2b586e5126f29fef7035e35c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|