whatisgithub

What is strif?

jlevy/strif — explained in plain English

Analysis updated 2026-05-18

129PythonAudience · developerComplexity · 1/5Setup · easy

In one sentence

A small dependency-free Python library with about 30 helper functions for safe file writing, IDs, hashing, and thread-safe values.

Mindmap

mindmap
  root((strif))
    What it does
      Atomic file writes
      Generate short IDs
      Hash strings and files
    Tech stack
      Python standard library
    Use cases
      Prevent corrupted files
      Sort IDs by time
      Share values across threads
    Audience
      Developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Write files atomically so a crash never leaves a partial or corrupted file.

USE CASE 2

Generate short, timestamp-sortable unique IDs with new_timestamped_uid.

USE CASE 3

Hash strings, files, or just filename and size for a fast comparison.

USE CASE 4

Share a value safely across threads using the AtomicVar wrapper.

What is it built with?

Python

How does it compare?

jlevy/strifbingook/bingolllyasviel/toondecompose
Stars129128130
LanguagePythonPythonPython
Last pushed2023-08-31
MaintenanceDormant
Setup difficultyeasymoderatehard
Complexity1/54/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

No external dependencies, only needs the Python standard library.

So what is it?

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.

Copy-paste prompts

Prompt 1
Show me how to use strif's atomic_write_text to safely write a file.
Prompt 2
How do I generate a timestamp-sortable unique ID with strif's new_timestamped_uid?
Prompt 3
Explain how strif's AtomicVar makes a value safe to share across threads.
Prompt 4
What does strif's fast file hash function check without reading the whole file?

Frequently asked questions

What is strif?

A small dependency-free Python library with about 30 helper functions for safe file writing, IDs, hashing, and thread-safe values.

What language is strif written in?

Mainly Python. The stack also includes Python.

How hard is strif to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is strif for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.