Skip to main content

Load and save json files as a global object

Project description

singlejson

GitHub issues PyPI

A very simple set of utilities for working with JSON in Python.

View the documentation here.

Features:

  • Easy loading of JSON files
  • Only one instance for each opened file
  • This library doesn't feature much more, just the basics

Installation:

Install singlejson using pip

pip install singlejson

Usage:

Loading JSON from file:

import singlejson

file = singlejson.load('file.json')  # Load file.json
# Returns a JSONfile object which has the json property
file.json["fun"] = True  # Edit some values in the JSONfile

But if we try to load the same file from the filesystem again, we get the same object:

import singlejson
file2 = singlejson.load('file.json')
print(file2.json["fun"])  # will output True

To save the file back to the disk we call file.save()
Maybe you don't want your program to save file contents only upon successful execution, then you just have to call singlejson.sync() at the end of your program to save all changes to the filesystem.

If the requested file doesn't exist, the file and its parent directories will be created and the "default" values will be written to the file. Should the root "node" of your JSON be a List, you may specify that the default to save is an empty list using singlejson.load(file, default="[]")

Building the documentation locally

The docs are configured to install via an optional dependency group in pyproject.toml (PEP 621). You don’t need a separate requirements.txt.

Quick steps:

# From the project root
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .[docs]

# Build HTML docs into docs/_build/html
python -m sphinx -b html docs/source docs/_build/html

Notes:

  • The Sphinx theme is furo. Versions are declared under [project.optional-dependencies].docs in pyproject.toml.
  • For a clean test, use a fresh virtual environment as shown above (preferred over uninstalling global packages).

Contributing:

This is just a fun project of mine mainly to try out python packaging. If you would like to contribute or have a feature-request, please open an issue or pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singlejson-0.3.2.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singlejson-0.3.2-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file singlejson-0.3.2.tar.gz.

File metadata

  • Download URL: singlejson-0.3.2.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for singlejson-0.3.2.tar.gz
Algorithm Hash digest
SHA256 a377922e81758f952b0b20508e0ee541a32a268d5c7fb9d42aa88dc50a65025d
MD5 20ff0a90058a8487c3ecd0734dd0210b
BLAKE2b-256 dab8a95e2629e00673121ba40f47bf2acfa53f7f6fbf66f79031942cf94e1139

See more details on using hashes here.

File details

Details for the file singlejson-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: singlejson-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for singlejson-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b689c05bdf09942caf5eea0a95b1d2043ee20006d25c8af7c3a69ced69d00e5
MD5 ac4bf635d30c739116ea2e4f5ec497c7
BLAKE2b-256 05a278919dfac2aa3cc204d7acb552cf883251bc0cb8c648cc8342f862a56744

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page