Skip to main content

A lightweight local JSON database

Project description

JSONLite

JSONLite is a lightweight, local JSON database for simple data storage.

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


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.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

jsonlite-0.0.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file jsonlite-0.0.3.tar.gz.

File metadata

  • Download URL: jsonlite-0.0.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for jsonlite-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a81446c4ece98cb0ec75074a44bad628398a7d212df29c4ad18008b091290a2a
MD5 d6ac27e47e8d539d183cba0d52792b24
BLAKE2b-256 2889bc4bd2d5390df19c29efd0c51eab6bd87f9d591648094b2332aa75ba4531

See more details on using hashes here.

File details

Details for the file jsonlite-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jsonlite-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for jsonlite-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0fe40a4d2f17928a74b274f2b777032f3d1bac8a674ccf4cd8de1904aac215cf
MD5 f0f9aca67f45cbecf11554dac8404c12
BLAKE2b-256 f332b59d7d3766dca7812433c8e3828b419b54eddf48d34a27b00a7a276370a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page