Skip to main content

A library for manage jsons files as dicts

Project description

SyJson - Sync variables to a json file in a simple way

What this library do?

This library make simple create a json file and read/write directly from this. This can be very useful and easy to use when we need to create small files such as a settings file, avoiding to write and read this manualy.

How to Install

You can install this library using PyPi (pip)

Linux / Windows / MacOs
pip3 install syjson

How to use

At first you can import SyJson class writing:

from syjson import SyJson

now we can use this class for create/read a json file pretty:int=None, bson:bool=False, cache:bool = True

synced_json = SyJson(
    "file.json",           #Path of the json file
    create_file = True,    #If the file does not exists,
                           #this will automatically create that file
    pretty = None,         #If setted to a number, the file will have an
                           #indentation of 'pretty' spaces
    cache = True,          #The file is readed only the first time with this option set to
                           #True, if your file have to be modified during the execution set this to false
                           #(Useful for debugging)
    encoding = "utf-8"     #JSON file encoding
)

This library use orjson for load and dump json files


There are some particular function added for particular use

--> synced_json.var()

With var function we can read from file the informations and we get a normal python object, so this python object have to be synced in a next step

--> synced_json.sync( value )

With sync function you can assign a variable and sync these informations in the target file

All SyJson object have these functionalityes


In Synced dicts there is an additional function that can be usefull in a lot of situation

--> synced_json.create( key, default_value )

This function create a pair of key and value if that key is not used in the json file and return the synced object, instead this function will simply return the synced object without overriding existing values.


Can bypass the use of sync function when you assign a value to a synced array of a synced dict in the json

f = SyJson("/path/to/file.json")

f["dict"] = {"num":0}
f["list"] = [1]

#Some operation that you can do without using sync function
f["dict"]["num"] = 1
f["dict"].keys()
f["dict"].values()
f["dict"].items()

f["list"][0] = 0
f["list"].append(1)
f["list"].pop()
f["list"].index(0)

By DomySh - me@domysh.com

--> https://domysh.com <--


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

syjson-2.1.6.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

syjson-2.1.6-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file syjson-2.1.6.tar.gz.

File metadata

  • Download URL: syjson-2.1.6.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for syjson-2.1.6.tar.gz
Algorithm Hash digest
SHA256 5d988515c5e974d14ad1f6af0e3f63bdf774e3c2157e5ff4fdb1cf536ca346c9
MD5 41c289fd4ee90e1d21ac58305e49cc08
BLAKE2b-256 db2f8691daa1a719da6c3fb5e72c6864137fc9caab7f9443c400b15058564b6f

See more details on using hashes here.

File details

Details for the file syjson-2.1.6-py3-none-any.whl.

File metadata

  • Download URL: syjson-2.1.6-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for syjson-2.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ee991fc1c82e7c301fa655cdbbcc7499c2428a575bc33553c904db9f761c173a
MD5 821f38333ed52cf114ded81844d63dfd
BLAKE2b-256 c6595b297dd8c005078504cb49b9a29359e16862803101697c9d21c80b6206c9

See more details on using hashes here.

Supported by

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