safeoutput
Safeoutput.open returns a file handle like object which can use used to write data to disk. It is meant to be used with python's with syntax.
If an exception is thrown, safeoutput automatically deletes the file. This ensures partially rendered output is not left sitting around.
If your handle leaves scope, without an exception being thrown, the file is atomically flipped into the desired location.
Safeoutput uses temporary files to store writes, so your file contents do not have to fit in memory.
Usage
Python
import sys
import safeoutput
def calc(line):
return line+1
input_fname = sys.argv[1]
output_fname = sys.argv[2]
with open(input_fname, 'r') as input:
with safeoutput.open(output_fname) as output:
for line in input.xreadlines():
output.write(str(calc(int(line))))
Command line
$ safeoutput
usage: safeoutput [-h] [--binary] FILE
The example below ensures bar is not written until the pipe is closed.
(sleep 10; echo foo ${RANDOM} ) | \
safeoutput --binary bar
cat bar
Metadata
Release files for safeoutput 3.0
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 | |
|---|---|---|---|---|
| safeoutput-3.0.tar.gz | 5.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| safeoutput-3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / safeoutput-3.0.tar.gz
| Download URL | safeoutput-3.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5f8cbf28914d425d53ad841721a435fcf0fc7e14d29755a3ae74637699e3e72
|
|
BLAKE2b-256 checksum How to use checksums |
3d8d363eca4b879028c1d0da4aad41621208b25f3e0789d26e9fe5027e4a5f12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / safeoutput-3.0-py3-none-any.whl
| Download URL | safeoutput-3.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
876165650a5321f774793991af551e4e1e078c71a24f95d2e242f3f57747819c
|
|
BLAKE2b-256 checksum How to use checksums |
23acca2cf311d1ae3b15eee9ea2136586ddc7deedb859a82bcb8d670a16307a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for safeoutput 3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.