kitsuyui.fileio
Small, explicit file I/O primitives. The first release provides atomic replacement of a single file without runtime dependencies (Python 3.10+).
from kitsuyui.fileio import atomic_write, atomic_write_bytes, atomic_write_text
atomic_write_text("settings.txt", "ready\n")
atomic_write_bytes("data.bin", b"\x00\x01")
with atomic_write("large.bin") as output:
output.write(b"first chunk")
output.write(b"second chunk")
atomic_write yields a binary stream. On normal exit it flushes and closes the
stream before replacing the destination. An exception inside the block leaves
the destination untouched and removes the temporary file when possible. Do not
close the yielded stream manually. The convenience functions accept paths and
bytes or text respectively; text is encoded as UTF-8 unless specified otherwise.
The parent directory must already exist. A caller that wraps the binary stream
in a TextIOWrapper must flush and detach the wrapper before leaving the block;
closing the supplied stream causes a ValueError and cancels replacement.
Text convenience writes use str.encode and do not translate newlines; callers
may choose the encoding and encoding error handler.
Guarantees and boundaries
The temporary file is created in the destination directory and installed with
os.replace. On a filesystem supporting POSIX atomic rename, a reader opening
the destination sees either the previous file or the complete new file during
normal execution; an
already-open descriptor may continue to refer to the old file. On other systems
and filesystems, replacement guarantees depend on the platform. This does not
lock writers, prevent lost updates, make multiple replacements transactional, or
secure a directory controlled by an untrusted party. Concurrent successful
writers are last-replacement-wins. A destination symlink itself is replaced;
its target is not modified. The temporary file is created with restrictive
permissions (0600 on POSIX). Existing ownership, permissions, timestamps, ACLs,
extended attributes and hard links are not preserved. The restrictive default
avoids silently exposing content from a private file or temporary write. To
choose another POSIX permission mode, pass permissions=0o644 (for example);
the specified bits are applied to the temporary file before replacement and
are not filtered by umask. Do not use permissive modes for sensitive data. On
Windows os.chmod has limited permission semantics. Copying existing permissions
is deliberately left to the caller because metadata and access policy are
platform-specific and can change concurrently.
The keyword durability distinguishes visibility from persistence:
"none": flush and close before replacement; nofsync."file"(default): alsofsyncthe staged file before replacement."file_and_directory": alsofsyncthe parent directory after replacement. This option is available only on POSIX and can still fail on a filesystem that does not support directory sync.
Sync calls request persistence from the operating system; they cannot guarantee
the behavior of every filesystem, storage device, or hardware buffer. A failure
before os.replace leaves an existing destination unchanged. If directory
sync fails after replacement, DurabilityError is raised: the new destination
is already visible, but its persistence is uncertain. If replacement itself fails,
the operating system error is propagated. Abrupt process termination can leave a
temporary file behind; ordinary exception cleanup is best effort. A crash with
"none" can leave the new file empty or truncated even after the rename, so
the runtime visibility guarantee is not a crash-recovery guarantee. On macOS,
os.fsync does not request the stronger F_FULLFSYNC operation, so even a
successful sync does not guarantee that hardware buffers reached durable media.
License
BSD 3-Clause License. See the repository's LICENSE.
Metadata
Release files for kitsuyui.fileio 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kitsuyui_fileio-0.8.1.tar.gz | 8.3 kB | With provenance | Details for kitsuyui_fileio-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kitsuyui_fileio-0.8.1-py3-none-any.whl | Python 3 | none | any | Details for kitsuyui_fileio-0.8.1-py3-none-any.whl |
Total release size: 15.2 kB
Release files / kitsuyui_fileio-0.8.1.tar.gz
| Download URL | kitsuyui_fileio-0.8.1.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
694d777b2a7151216a026c9c1d846e17090ff797978804e098a291c5e99ef54c
|
|
BLAKE2b-256 checksum How to use checksums |
1aa0bc9765da2865f434736c09f2c5f360f4e7c5149a324015c1ca974e941395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / kitsuyui_fileio-0.8.1-py3-none-any.whl
| Download URL | kitsuyui_fileio-0.8.1-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d75360baa9c7207f4f15724a8103418f7088293e13ac7b8314137cabcc09609
|
|
BLAKE2b-256 checksum How to use checksums |
7fd3646ad7e2ef721d94d389aecc478b1cb869425b249b2837c6a6d18ccfb1af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for kitsuyui.fileio 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for kitsuyui_fileio-0.8.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.