Typing stubs for atomicwrites

1.4.5.1 · deprecated · verified Thu Apr 16

types-atomicwrites is a PEP 561 type stub package for the atomicwrites library, currently at version 1.4.5.1. It provides type annotations for use by static type checkers like MyPy and PyCharm. While it is part of the broader typeshed project, this specific stub package is explicitly noted as unmaintained and will not be updated. Furthermore, the underlying atomicwrites library itself has been marked as deprecated by its original maintainer, who recommends using Python 3's built-in os.replace or os.rename functions for most atomic file writing needs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform an atomic file write using the `atomicwrites` library. Installing `types-atomicwrites` alongside `atomicwrites` will enable static type checking for this code.

from atomicwrites import atomic_write

def save_data_atomically(filename: str, content: str):
    try:
        with atomic_write(filename, overwrite=True) as f:
            f.write(content)
        print(f"Successfully wrote to {filename}")
    except Exception as e:
        print(f"Error writing to {filename}: {e}")

# Example usage:
save_data_atomically("my_config.txt", "config_key=value\nother_setting=123")

view raw JSON →