Welcome to singlejson’s documentation!¶
Singlejson is a tiny helper to load and save JSON files as shared objects across your codebase. It offers a friendly JSONFile wrapper, a thread‑safe pool for shared instances, and configurable serialization.
Installation & basic usage¶
Install with pip:
Here is a quick example to get you started:
from singlejson import JSONFile, load, sync, JsonSerializationSettings
# Work with a single file
with JSONFile("settings.json", default_data={"theme": "dark"}) as jf:
jf.json["count"] = 1 # saved automatically on clean exit
# Shared instance via pool
jf = load("data.json", default_data={})
jf.json["x"] = 42
sync() # persist all pooled files
# Control formatting
jf.settings = JsonSerializationSettings(indent=2, sort_keys=True, ensure_ascii=False)
jf.save()
Get started in a minute using the guide below, or dive into the API reference.
Guide
API Reference