Registry / serialization / atomicwrites-homeassistant

atomicwrites-homeassistant

JSON →
library1.4.1pypypi✓ verified 85d ago

A fork of the `atomicwrites` library, `atomicwrites-homeassistant` provides atomic file writes in Python. It ensures that file writes are all-or-nothing operations, preventing data corruption in case of crashes or interruptions. The `homeassistant` fork specifically addresses maintenance issues of the original `atomicwrites` package and is currently at version 1.4.1. It is a dependency for Home Assistant and other projects requiring reliable file operations.

pip install atomicwrites-homeassistant
INSTALL
IMPORT
SIG · ATOMICWRITES-HOMEA
A
atomicwrites-homeassistant
serializationpythonv1.4.1
Install
1.5s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.011s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

atomic_write
from atomicwrites import atomic_write

This example demonstrates how to use `atomic_write` as a context manager to ensure that file writing is an atomic operation. The `overwrite=True` parameter ensures that if the file already exists, it will be safely replaced.

from atomicwrites import atomic_write file_path = 'my_atomic_file.txt' content = 'Hello, atomic world!' # Perform an atomic write, overwriting if the file exists with atomic_write(file_path, overwrite=True) as f: f.write(content) print(f"Content written to {file_path} atomically.")
Debug
Known issues
gotchaThe `atomicwrites-homeassistant` package is a fork created because the original `atomicwrites` library was unmaintained. Users should be aware they are using this Home Assistant-specific fork, which provides continued maintenance.
fix
Ensure you are installing `atomicwrites-homeassistant` when intending to use the Home Assistant-maintained version.
affects: All versions
gotchaOn Windows, the atomicity guarantee for file moves (using `MoveFileEx` via `ctypes`) is not absolute; it may silently fall back to a non-atomic method in some cases. If strict atomicity is critical on Windows, additional safeguards or alternative methods may be required.
fix
Do not solely rely on the library for guaranteed atomicity on Windows without additional validation or error handling for critical operations. Consider alternative strategies if absolute atomicity is a must-have.
affects: All versions
gotchaWhen running Home Assistant in Docker and using individually bind-mounted configuration files (e.g., for automations or scripts), atomic writes can lead to an `OSError: [Errno 16] Resource busy`. This prevents UI editors from saving changes to these files.
fix
To resolve this, avoid bind-mounting individual configuration files. Instead, bind-mount the parent directory (e.g., `/config`) or use Docker volumes. Alternatively, edit these files directly on the host or accept that UI editing will not work for bind-mounted files.
affects: All versions with Docker bind mounts
gotchaOn POSIX systems, there is a small time window during `link` and `unlink` operations where the file might be accessible under both its temporary name and the target name. Additionally, file permissions of the target file may change and are not automatically preserved by the library due to concurrency concerns.
fix
Be aware of potential dual file entries during a brief transition period. If preserving specific permissions is crucial, implement explicit `chmod` calls after the atomic write, considering concurrency implications.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'atomicwrites_homeassistant'
The 'atomicwrites-homeassistant' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install atomicwrites-homeassistant'.
ImportError: cannot import name 'atomic_write' from 'atomicwrites_homeassistant'
The module is named 'atomicwrites', not 'atomicwrites_homeassistant'.
fix
Use the correct import statement: 'from atomicwrites import atomic_write'.
ModuleNotFoundError: No module named 'sqlalchemy'
The 'sqlalchemy' package is not installed, which is a dependency for some components.
fix
Install the package using pip: 'pip install sqlalchemy'.
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: 'RECORD'
Insufficient permissions to write to the installation directory.
fix
Run the installation command with elevated privileges: 'sudo pip install homeassistant'.
ModuleNotFoundError: No module named '_sqlite3'
The Python installation lacks the SQLite module, which is required for database operations.
fix
Reinstall Python ensuring that the SQLite development headers are present during compilation.
Upgrade
Version history
1.4.1latest on PyPI · released Jul 8, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources