Write files atomically so a crash never leaves a partial or corrupted file.
Generate short, timestamp-sortable unique IDs with new_timestamped_uid.
Hash strings, files, or just filename and size for a fast comparison.
Share a value safely across threads using the AtomicVar wrapper.
| jlevy/strif | bingook/bingo | lllyasviel/toondecompose | |
|---|---|---|---|
| Stars | 129 | 128 | 130 |
| Language | Python | Python | Python |
| Last pushed | — | — | 2023-08-31 |
| Maintenance | — | — | Dormant |
| Setup difficulty | easy | moderate | hard |
| Complexity | 1/5 | 4/5 | 4/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
No external dependencies, only needs the Python standard library.
strif is a small Python utility library, roughly 1,000 lines of code, that provides about 30 helper functions for common string, file, and object tasks. It has no external dependencies, requiring only the Python standard library. The most practically useful part is the atomic file writing section. When a program writes a file and crashes or is interrupted halfway through, the result is a partial or corrupted file at the intended location. The strif approach is to write to a temporary file first, then rename it to the final location only after writing completes successfully. The library provides a context manager called atomic_output_file and convenience functions like atomic_write_text and atomic_write_bytes that handle this pattern automatically, including creating parent directories and optionally saving a backup of any file that gets overwritten. For generating identifiers, strif uses base 36 encoding (digits plus letters, case-insensitive). This produces shorter IDs than hex while avoiding special characters that cause problems in filenames. Two main functions are provided: new_uid for a random ID and new_timestamped_uid for an ID that starts with an ISO timestamp, making a list of IDs sort naturally by creation time. For hashing, strif wraps Python's standard hashlib with a small class that makes it easy to output the result in hex, base 36, or other forms. There are separate functions for hashing strings, file contents, and a fast path that hashes just the filename, size, and modification time without reading the file. The library also includes AtomicVar, a thread-safe wrapper around any value that combines the value with a reentrant lock, making safe concurrent access straightforward. Rounding out the library are small utilities for abbreviating long strings in logs, doing multiple string replacements in one pass, and a validated string template class that rejects unknown field names at format time.
A small dependency-free Python library with about 30 helper functions for safe file writing, IDs, hashing, and thread-safe values.
Mainly Python. The stack also includes Python.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.