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:

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.0.tar.gz (28.3 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.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: singlejson-0.3.0.tar.gz
  • Upload date:
  • Size: 28.3 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.0.tar.gz
Algorithm Hash digest
SHA256 42611653955e5be1bc28a862e098d0d6b22311a35c288731ce112d22b706a57d
MD5 3dac5440d3ac0a3cb2cf6b85fe663716
BLAKE2b-256 7538ea5d1db0ff867bae5e40b1933177439ddfc1d7668a043343b314b6658f3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: singlejson-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b39730ce5e2c584582b7f9042106d07fadd79e2e6dab4544e627405c55a1165
MD5 a323863ca2cf4bcf206ba347223ae40d
BLAKE2b-256 7a9d126e223725ebdc97b649fc2ca5911848aca1ed0f324911f2413a19d75f93

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