Kivi.py 🥝
from kivi import Kivi
db = Kivi()
db.kv_create("mydb", {"greeting-1": "Good morning 🌅"})
A simple key-value database that uses JSON to store data
Supported data types
- String
- Boolean
- Integer
- Float
- Lists
- Dict
- Datetime
Why?
I just wanted a simple database to play around, why everything is so complex
Install
pip install kivi.py
Usage
Initialize database
from kivi import Kivi
db = Kivi(
src="Where the database files should be stored. Defaults to `os.getcwd()/.kivi_db`",
to_load=["path/to/file.json"])
Create
Creates a new database and load it to the memory
-
Arguments:
name: Name of the databasedata: Dict consist of data
-
Example:
db.kv_create("wow", {"user-1": 123456})
Load
Loads database into the memory
-
Arguments:
data: Path to a json file or python dict
-
Returns: Index of the database
-
Example:
db.kv_load("/home/test/data/stuff.json")
Get
Get value from a database
-
Arguments:
index: Index of the database (returned in kv_load or when creating the instance)key: Key!
-
Example:
db.kv_get(0, "greeting")
Set / Update
Add or update key in a database
-
Arguments:
index: Index of the database (returned in kv_load or when creating the instance)key: Key!
-
Example:
db.kv_set(0, "gtr1", "greeting")
Merge
Merge data into the database
-
Arguments:
index: Index of the database (returned in kv_load or when creating the instance)tomerge: Dict consist of data that needs to be merged
-
Example:
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)
Index
Index data to perform queries much faster
-
Arguments:
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)
Query
Search for string in an indexed database
-
Arguments:
index: Index of the database (returned in kv_load or when creating the instance)query: String to search for in the database
-
Example:
db.kv_query(0, "Spider man")
Search
Search for string in a database
-
Arguments:
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 results
-
Example:
db.kv_search(0, "Spider man")
How it works
Data is stored inside json files in the following format
{
"name": "lot",
"items": {...}
}
items contains 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 using kv_get function, data will be automatically converted back to it's original type (limitations)
Requirements
- Python 3.5+
Limitations
The 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
Metadata
Release files for kivi.py 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kivi.py-0.1.2.tar.gz | 9.4 kB | Details |
Release files / kivi.py-0.1.2.tar.gz
| Download URL | kivi.py-0.1.2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fd58138c3a5d556da6296e073fdbd3ccef3fdadcb0926a10cd887a7622c0769
|
|
BLAKE2b-256 checksum How to use checksums |
1fc8f4ff713a5e9dbfb665180b734bd2453e35c47007235fd0e78affe3eca42e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|