pyfastkvjson


Namepyfastkvjson JSON
Version 3.1.16 PyPI version JSON
download
home_pagehttps://github.com/ONode/pyfastkvjson/
SummaryJson key store with secured feature.
upload_time2023-03-23 17:52:30
maintainer
docs_urlNone
authorOliver Bristow, Heskemo
requires_python
licenseMIT
keywords json key value store and more secured
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            |PyPi Package| |Build Status| |Codacy Rating|

run command to install
======================

`pip install pyfastkvjson`

jsonstore kv
============

This module provides a class that maps keys and values from a JSON file
onto its attributes.

The goal was to provide a convenient way of loading and saving
configuration in a familiar human readable format. This is a bit more
flexible than the
`configparser <https://docs.python.org/3/library/configparser.html>`__
module which is included with Python.

This works is tested and working on Python 2.7+ and Python 3.3+. It will
not work on 2.6 or lower, but is expected to work on 3.0-3.2. The tests
do not work in 3.2.6 due to
`mistreating <https://travis-ci.org/Code0x58/python-jsonstore/jobs/198150401>`__
the 💩 when parsing the test code. This is also tested on pypy and pypy3.

Examples
--------

Basics
~~~~~~

.. code:: python

    # by default JsonStore commits on every change unless in a transaction
    store = JsonStore('config.json')
    store.a_string = "something"
    store.a_list = [1, 2, 3]
    store.a_dictionary = {
      'dict-list': [{}],
      'ln(2)': 0.69314718056,
      'for-you': u"💐",
    }

    # you can use […] to set/get/delete string keys
    store['some_key'] = "a value"
    # the key is split on '.'s and works on dictionaries
    del store['a_dictionary.dict-list']
    store['a_dictionary.new_value'] = "old value"
    #  you can also use the syntactic sugar for tuple keys (explicit lists work too)
    assert store['a_dictionary', 'new_value'] == "old value"
    # you can traverse lists too
    assert store['a_list', -1] == 3
    # you can use slices in lists
    assert len(store['a_list', 1:]) == 2

    # deep copies are made when assigning values
    my_list = ['fun']
    store.a_list = my_list
    assert store.a_list is not my_list
    assert 'a_list' in store

    # deep copies are also returned to avoid unsanitary changes being made
    store.a_dictionary['new_value'] = "new value"  # won't update the store!
    assert store.a_dictionary['new_value'] == "old value"
    assert store.a_dictionary is not store.a_dictionary

    # Appending to, extending a list
    >>> store.list = [1, 2, 3]

    # Because of the fact that .append won't modify the list in the actual file,
    # but only a copy...
    >>> store.list.append(4)
    >>> store.list
    [1, 2, 3]

    # ... we need to rather use the += operator to append to a list.
    >>> store.list += [4]
    >>> store.list
    [1, 2, 3, 4]

    # Similarly, we can extend the list
    >>> store.list += [5, 6]
    >>> store.list
    [1, 2, 3, 4, 5, 6]

Additional encryptions
~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    TEST_PASSWORD="123456"
    secret_file_name = mktemp() + ".aes"
    store_ram = JsonStore(secret_file_name, indent=None, auto_commit=True, password=TEST_PASSWORD)

Transactions
~~~~~~~~~~~~

``JsonStore`` objects can be used as `context
managers <https://www.python.org/dev/peps/pep-0343/>`__ to provide
transactions which are rolled back in the event of an exception. The
transaction model is primitive; you can only nest transactions.

While a store is put into a transaction, it will not save changes to
file until all of the transactions have been closed.

.. code:: python

    from jsonstore import JsonStore

    # even with auto_commit=True, the file won't be saved until the last contexts has been closed
    with JsonStore('config.json', indent=None, auto_commit=False) as store:
      self.value = 1

    # the context manager will roll back changes made if an exception is raised
    store = JsonStore('config.json', indent=None)
    try:
      with store:
        store.value = "new"
        raise Exception
    except Exception:
      pass
    # here we see the value that was saved previously
    assert store.value == 1

.. |Build Status| image:: https://travis-ci.org/ONode/pyfastkvjson.svg?branch=master
   :target: https://travis-ci.org/ONode/pyfastkvjson
.. |Codacy Rating| image:: https://api.codacy.com/project/badge/Grade/37ea488773444de59469a3775be83faf
   :target: https://www.codacy.com/app/evilumbrella-github/python-jsonstore?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ONode/pyfastkvjson&amp;utm_campaign=Badge_Grade
.. |PyPi Package| image:: https://badge.fury.io/py/python-jsonstore.svg
   :target: https://pypi.org/project/python-jsonstore/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ONode/pyfastkvjson/",
    "name": "pyfastkvjson",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "json key value store and more secured",
    "author": "Oliver Bristow, Heskemo",
    "author_email": "github+pypi@oliverbristow.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/d5/f4/31a3dd0beb7aa02a94a2af0482f81c0df9274e22cba90b31e89f99d44a98/pyfastkvjson-3.1.16.tar.gz",
    "platform": null,
    "description": "|PyPi Package| |Build Status| |Codacy Rating|\n\nrun command to install\n======================\n\n`pip install pyfastkvjson`\n\njsonstore kv\n============\n\nThis module provides a class that maps keys and values from a JSON file\nonto its attributes.\n\nThe goal was to provide a convenient way of loading and saving\nconfiguration in a familiar human readable format. This is a bit more\nflexible than the\n`configparser <https://docs.python.org/3/library/configparser.html>`__\nmodule which is included with Python.\n\nThis works is tested and working on Python 2.7+ and Python 3.3+. It will\nnot work on 2.6 or lower, but is expected to work on 3.0-3.2. The tests\ndo not work in 3.2.6 due to\n`mistreating <https://travis-ci.org/Code0x58/python-jsonstore/jobs/198150401>`__\nthe \ud83d\udca9 when parsing the test code. This is also tested on pypy and pypy3.\n\nExamples\n--------\n\nBasics\n~~~~~~\n\n.. code:: python\n\n    # by default JsonStore commits on every change unless in a transaction\n    store = JsonStore('config.json')\n    store.a_string = \"something\"\n    store.a_list = [1, 2, 3]\n    store.a_dictionary = {\n      'dict-list': [{}],\n      'ln(2)': 0.69314718056,\n      'for-you': u\"\ud83d\udc90\",\n    }\n\n    # you can use [\u2026] to set/get/delete string keys\n    store['some_key'] = \"a value\"\n    # the key is split on '.'s and works on dictionaries\n    del store['a_dictionary.dict-list']\n    store['a_dictionary.new_value'] = \"old value\"\n    #  you can also use the syntactic sugar for tuple keys (explicit lists work too)\n    assert store['a_dictionary', 'new_value'] == \"old value\"\n    # you can traverse lists too\n    assert store['a_list', -1] == 3\n    # you can use slices in lists\n    assert len(store['a_list', 1:]) == 2\n\n    # deep copies are made when assigning values\n    my_list = ['fun']\n    store.a_list = my_list\n    assert store.a_list is not my_list\n    assert 'a_list' in store\n\n    # deep copies are also returned to avoid unsanitary changes being made\n    store.a_dictionary['new_value'] = \"new value\"  # won't update the store!\n    assert store.a_dictionary['new_value'] == \"old value\"\n    assert store.a_dictionary is not store.a_dictionary\n\n    # Appending to, extending a list\n    >>> store.list = [1, 2, 3]\n\n    # Because of the fact that .append won't modify the list in the actual file,\n    # but only a copy...\n    >>> store.list.append(4)\n    >>> store.list\n    [1, 2, 3]\n\n    # ... we need to rather use the += operator to append to a list.\n    >>> store.list += [4]\n    >>> store.list\n    [1, 2, 3, 4]\n\n    # Similarly, we can extend the list\n    >>> store.list += [5, 6]\n    >>> store.list\n    [1, 2, 3, 4, 5, 6]\n\nAdditional encryptions\n~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    TEST_PASSWORD=\"123456\"\n    secret_file_name = mktemp() + \".aes\"\n    store_ram = JsonStore(secret_file_name, indent=None, auto_commit=True, password=TEST_PASSWORD)\n\nTransactions\n~~~~~~~~~~~~\n\n``JsonStore`` objects can be used as `context\nmanagers <https://www.python.org/dev/peps/pep-0343/>`__ to provide\ntransactions which are rolled back in the event of an exception. The\ntransaction model is primitive; you can only nest transactions.\n\nWhile a store is put into a transaction, it will not save changes to\nfile until all of the transactions have been closed.\n\n.. code:: python\n\n    from jsonstore import JsonStore\n\n    # even with auto_commit=True, the file won't be saved until the last contexts has been closed\n    with JsonStore('config.json', indent=None, auto_commit=False) as store:\n      self.value = 1\n\n    # the context manager will roll back changes made if an exception is raised\n    store = JsonStore('config.json', indent=None)\n    try:\n      with store:\n        store.value = \"new\"\n        raise Exception\n    except Exception:\n      pass\n    # here we see the value that was saved previously\n    assert store.value == 1\n\n.. |Build Status| image:: https://travis-ci.org/ONode/pyfastkvjson.svg?branch=master\n   :target: https://travis-ci.org/ONode/pyfastkvjson\n.. |Codacy Rating| image:: https://api.codacy.com/project/badge/Grade/37ea488773444de59469a3775be83faf\n   :target: https://www.codacy.com/app/evilumbrella-github/python-jsonstore?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ONode/pyfastkvjson&amp;utm_campaign=Badge_Grade\n.. |PyPi Package| image:: https://badge.fury.io/py/python-jsonstore.svg\n   :target: https://pypi.org/project/python-jsonstore/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Json key store with secured feature.",
    "version": "3.1.16",
    "split_keywords": [
        "json",
        "key",
        "value",
        "store",
        "and",
        "more",
        "secured"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da3b7d1aeaac56c22e5bc3955691c321bdbe4d6c8d76491243ab873d0f1f5d12",
                "md5": "55960ae0ad1e99b9b65d1830c6ff0e91",
                "sha256": "3bee4f6ee81f7e9d460dc1efc5c6376e4f150d831c14ca67fe0fa53107d53cf2"
            },
            "downloads": -1,
            "filename": "pyfastkvjson-3.1.16-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55960ae0ad1e99b9b65d1830c6ff0e91",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 6578,
            "upload_time": "2023-03-23T17:52:28",
            "upload_time_iso_8601": "2023-03-23T17:52:28.404845Z",
            "url": "https://files.pythonhosted.org/packages/da/3b/7d1aeaac56c22e5bc3955691c321bdbe4d6c8d76491243ab873d0f1f5d12/pyfastkvjson-3.1.16-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5f431a3dd0beb7aa02a94a2af0482f81c0df9274e22cba90b31e89f99d44a98",
                "md5": "c46f32788bf4ee801094608d90ec34e9",
                "sha256": "1df9ccaa469cf17bc1d1fa55ec00381bfd2c813e307f3a84c3eb31e8ed350cf0"
            },
            "downloads": -1,
            "filename": "pyfastkvjson-3.1.16.tar.gz",
            "has_sig": false,
            "md5_digest": "c46f32788bf4ee801094608d90ec34e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 159400,
            "upload_time": "2023-03-23T17:52:30",
            "upload_time_iso_8601": "2023-03-23T17:52:30.581228Z",
            "url": "https://files.pythonhosted.org/packages/d5/f4/31a3dd0beb7aa02a94a2af0482f81c0df9274e22cba90b31e89f99d44a98/pyfastkvjson-3.1.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-23 17:52:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ONode",
    "github_project": "pyfastkvjson",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyfastkvjson"
}
        
Elapsed time: 1.19921s