parq_tools.utils.file_utils.atomic_output_file

parq_tools.utils.file_utils.atomic_output_file(final_file, suffix='.tmp')[source]

Context manager for atomic file writes using a temporary file.

All writes are directed to a temporary file in the same directory. On successful exit, the temp file is atomically renamed to the final path. On error, the temp file is deleted.

Example

with atomic_output_file(output_path) as tmp_file:
    # Write to tmp_file
    pq.write_table(table, tmp_file)
Parameters:
  • final_file (Path) – The intended final output file path.

  • suffix (str) – Suffix for the temporary file (default: “.tmp”).

Return type:

ContextManager[Path]