Skip to main content

Atomic file writes.

Project description

https://travis-ci.org/untitaker/python-atomicwrites.svg?branch=master https://ci.appveyor.com/api/projects/status/vadc4le3c27to59x/branch/master?svg=true

Atomic file writes.

Features that distinguish it from other similar libraries:

  • Race-free assertion that the target file doesn’t yet exist. This can be controlled with the overwrite parameter.

  • Windows support, although untested. The MSDN resources are not very explicit about which operations are atomic. This requires pywin32.

  • Simple high-level API that wraps a very flexible class-based API.

Usage:

from atomicwrites import atomic_write

with atomic_write('foo.txt') as f:
    f.write('Hello world.')
    # "foo.txt" doesn't exist yet.

# Now it does.

How it works

It uses a temporary file in the same directory as the given path. This ensures that the temporary file resides on the same filesystem.

The temporary file will then be atomically moved to the target location: On POSIX, it will use rename if files should be overwritten, otherwise a combination of link and unlink. On Windows, it uses MoveFileEx (see MSDN) with the appropriate flags.

Note that with link and unlink, there’s a timewindow where the file might be available under two entries in the filesystem: The name of the temporary file, and the name of the target file.

License

Licensed under the MIT, see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atomicwrites-0.1.3.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atomicwrites-0.1.3-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file atomicwrites-0.1.3.tar.gz.

File metadata

  • Download URL: atomicwrites-0.1.3.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for atomicwrites-0.1.3.tar.gz
Algorithm Hash digest
SHA256 54b5670375f85281db4eb244e374fc4fbeeea409039fd6f559e48b2e899bc8b5
MD5 46718419abd1767fc2fdf25366f5d2d9
BLAKE2b-256 ae176f7d8499d31051c4c407aad555507ef331cca76062dfcd8050b6fb629bab

See more details on using hashes here.

File details

Details for the file atomicwrites-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: atomicwrites-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for atomicwrites-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 325695964342ab6ba553ebf12c7c29e99ddfd2826ead22893a99cd8ea02c1302
MD5 8cd00483ecc934519dc77521914ceef4
BLAKE2b-256 6a310f57245fce8cb88ae6afcbbd4d8a243745d47da7f2b6cf37d93580b72b95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page