phenotypic.sdk_.atomic_write_text#

phenotypic.sdk_.atomic_write_text(path: str | Path, text: str, *, encoding: str = 'utf-8') None[source]#

Atomically write text to path (temp sibling + os.replace).

A drop-in replacement for Path(path).write_text(text) that never leaves a half-written file: a concurrent reader sees either the old contents or the complete new ones, and an exception mid-write leaves any pre-existing file intact with no .tmp debris.

Parameters:
  • path (str | Path) – The destination file path.

  • text (str) – The full text payload to write.

  • encoding (str) – The text encoding (default "utf-8").

Raises:

OSError – If the write or rename fails (the temp file is removed first).

Return type:

None