Skip to content

EncryptedBetterJSONStorage is a faster 'Storage Type' for TinyDB by taking BetterJSONStorage & TinyDB JSONStorage as base.

License

Notifications You must be signed in to change notification settings

groverankur/EncryptedBetterJSONStorage

Repository files navigation

https://github.com/groverankur/EncryptedBetterJSONStorage/blob/965cbd755a9f1d7c2424c73f2bf659d642c3de67/img/logo.png

Introduction

EncryptedBetterJSONStorage is a faster 'Storage Type' for TinyDB by taking BetterJSONStorage & TinyDB JSONStorage as base. It uses the faster Orjson library for parsing the JSON , BLOSC2 for compression and cryptography for encryption.

Parsing, compressing, and writing to the file is done by a seperate thread so reads don't get blocked by slow fileIO. Smaller filesizes result in faster reading and writing (less diskIO). Even Reading is all done from memory.

These optimizations result in much faster reading and writing without loss of functionality.

A goal for the EncryptedBetterJSONStorage project is to provide a drop in replacement for the default JSONStorage with added functionality of encryption and compression.

An example of how to implement EncryptedBetterJSONStorage can be found below. Anything else can be found in the TinyDB docs.

Installing EncryptedBetterJSONStorage

Install EncryptedBetterJSONStorage as follows

python setup.py install

Usage

context Manager

from tinydb import TinyDB
from EncryptedBetterJSONStorage import EncryptedBetterJSONStorage

path = 'relative/path/to/file.db'

with TinyDB(path,encryption_key=b"KeY", encryption=True ,compression=True, access_mode="r+", storage=EncryptedBetterJSONStorage) as db:
    db.insert({'int': 1, 'char': 'a'})
    db.insert({'int': 1, 'char': 'b'})

extra

one difference from TinyDB default JSONStorage is that BetterJSONStorage is ReadOnly by default. use access_mode='r+' or 'rb+' if you want to write as well.

All arguments except for the storage and access_mode argument are forwarded to the underlying storage. You can use this to pass additional keyword arguments to orjson.dumps(…) method.

For all options see the orjson documentation.

with TinyDB('file.db',encryption_key=b"KeY", encryption=True ,compression=True, option=orjson.OPT_NAIVE_UTC, storage=BetterEncryptedJSONStorage) as db:

Change encryption key

You can change the encryption key of the storage by accessing the storage property of your TinyDB docs database.

db = ...
db.storage.change_encryption_key("NEW_KEY")

About

EncryptedBetterJSONStorage is a faster 'Storage Type' for TinyDB by taking BetterJSONStorage & TinyDB JSONStorage as base.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages