Package: kivi.py
Kivi.py 🥝fromkiviimportKividb=Kivi()db.kv_create("mydb",{"greeting-1":"Good morning 🌅"})A simple key-value database that usesJSONto store dataSupported data typesStringBooleanIntegerFloatListsDictDatetimeWhy?I just wanted a simple database to play around, why everything is so complexInstallpip install kivi.pyUsageInitCreateLoadGetSet / UpdateMergeIndexQuerySearchInitialize databasefromkiviimportKividb=Kivi(src="Where the database files should be stored. Defaults to `os.getcwd()/.kivi_db`",to_load=["path/to/file.json"])[!NOTE]to_loadonly takes json file with default kivi format.
If you want to store regular json data usecreateormergeCreateCreates a new database and load it to the memoryArguments:name: Name of the databasedata: Dict consist of dataExample:db.kv_create("wow",{"user-1":123456})Load[!Note]
It is recommended to load databases when initializing the database withKivi(to_load=[...])Loads database into the memoryArguments:data: Path to a json file or python dictReturns:
Index of the databaseExample:db.kv_load("/home/test/data/stuff.json")GetGet value from a databaseArguments:index: Index of the database (returned in kv_load or when creating the instance)key: Key!Example:db.kv_get(0,"greeting")Set / UpdateAdd or update key in a databaseArguments:index: Index of the database (returned in kv_load or when creating the instance)key: Key!Example:db.kv_set(0,"gtr1","greeting")MergeMerge data into the databaseArguments:index: Index of the database (returned in kv_load or when creating the instance)tomerge: Dict consist of data that needs to be mergedExample:dt={"thing-1":[123,True,{'user1':'gibberish?#45'}],"thing-2":[123,True,{'user2':'gibberish?#45','nuh':True}]}db.kv_merge(index=0,tomerge=dt,to_std=True)[!Note]
If thetomergedict is not in the kivi formatting, setto_std = TrueIndexIndex data to perform queries much fasterArguments:data: Data to index (a dict or list of dicts)fields: Json fields that needs to be indexedchars: Amount of characters that indexed key can have (Ex: "Spider" will be sliced to "spi" to create the key for index)Example:data=[{"title":"Spooder man","extract":"Marvel spooder man!"},{"title":"Iron deficiency man","extract":"Marvel no Fe?"}]db.kv_index(data,["title","extract"],3)QuerySearch for string in an indexed databaseArguments:index: Index of the database (returned in kv_load or when creating the instance)query: String to search for in the databaseExample:db.kv_query(0,"Spider man")SearchSearch for string in a databaseArguments:index: Index of the database (returned in kv_load or when creating the instance)query: String to search for in the databasestrict: Pass 'False' to get more resultsExample:db.kv_search(0,"Spider man")How it worksData is stored inside json files in the following format{"name":"lot","items":{...}}itemscontains the inserted data as a string alongside it's original data type like this,{"name":"lot","items":{"thing-1":["{'user': 'gibberish?#45'}","dict"],"thing-2":["{'user': 'gibberish?#45'}","dict"]}}When you request data usingkv_getfunction, data will be automatically converted back to it's original type (limitations)RequirementsPython 3.5+dependeciesLimitationsThe data convertion has lots of limits as of now (I don't plan of updating this either).For example:Complex json structures will fail to convert