A lightweight local JSON database
Project description
JSONLite
JSONLite is a lightweight, local JSON database for simple data storage.
- Like SQLite, it's a local database
- It's API is 100% modeled after MongoDB, making it easy to migrate between MongoDB and JSONLite
Installation
pip install jsonlite
Data Layout
{
"data": [
{ "_id": 1,
"name": "Alice",
"age": 30
},
{ "_id": 2,
"name": "Bob",
"age": 25
},
{ "_id": 3,
"name": "Charlie",
"age": 20
}
]
}
Usage
from jsonlite import JSONlite
db = JSONlite('db.json')
# insert
db.insert_one({'name': 'Alice', 'age': 30})
db.insert_one({'name': 'Bob', 'age': 25})
db.insert_many([
{'name': 'Charlie', 'age': 20},
{'name': 'Tom', 'age': 15}])
# find
all_records = db.find()
one_record = db.find_one()
age_over_20 = db.find({'age': (gt, 20)})
# update
db.update_one({'name': 'Alice'}, {'age': 31})
_id = db.find_one({'name': 'Alice'})['_id']
db.update_one({'_id': _id}, {'age': 35})
# delete
db.delete_one({'name': 'Bob'})
db.delete_many({'name': 'Bob'})
# complex find
records_with_name_alice_or_age_30 = db.find({'or': [
{'name': 'Alice'},
{'age': 30}]
})
records_with_name_alice_and_age_30 = db.find({'and': [
{'name': 'Alice'},
{'age': 30}
]})
# custom functions in conditions
def is_even(value):
return value % 2 == 0
records_with_even_age = db.find({'age': is_even})
def is_multiple_of(value, match_value):
return value % match_value == 0
records_with_age_multiple_of_5 = db.find({'age': (is_multiple_of, 5)})
def is_between(value, min_value, max_value):
return min_value < value < max_value
records_between_10_and_30 = self.db.find({'age': (is_between, 10, 30)})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonlite-0.0.4.tar.gz
(8.4 kB
view details)
Built Distribution
jsonlite-0.0.4-py3-none-any.whl
(10.4 kB
view details)
File details
Details for the file jsonlite-0.0.4.tar.gz
.
File metadata
- Download URL: jsonlite-0.0.4.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d05ea0f3c7f4c1057a048db0f260495ea70a5b8a8bd623eb44efd89d78dcbcbb |
|
MD5 | 6ba2445f34d9bff96f4b6cbf1d00818a |
|
BLAKE2b-256 | 728365788a3fa54d5a958dc465a0f2d106fa683eaf869871bfd59a1f35d447bd |
File details
Details for the file jsonlite-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: jsonlite-0.0.4-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4a03a3033fa413e045a53a66263af98fa2d72a9fd90a59950f3512498a5b73a |
|
MD5 | 28e13fe154da9e6e0267de55c1b6c03f |
|
BLAKE2b-256 | 575493b368d5c922e110d9a16f018673255a4cb2676e45c3ce6284193b95ed4b |