LightDB: Lightweight JSON Database for Python
You can install LightDB using pip:
pip install lightdb
To use LightDB, first import the LightDB
class from the lightdb
package:
from lightdb import LightDB
Then, create a LightDB
object by passing in the path to a JSON file where the database will be stored:
db = LightDB("my_database.json")
You can then set key-value pairs in the database using the set()
method:
db.set("name", "Alice")
db.set("age", 30)
You can get the value associated with a key using the get()
method:
name = db.get("name")
age = db.get("age")
You can also remove a key-value pair using the pop()
method:
db.pop("age")
To reset the database to an empty state, use the reset()
method:
db.reset()
After making the changes, you need to save()
:
db.save()