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

Uploaded Source

Built Distribution

jsonlite-0.0.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonlite-0.0.2.tar.gz
  • Upload date:
  • Size: 7.7 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.2.tar.gz
Algorithm Hash digest
SHA256 3eee54422a0835efe821532bb8ac51679df4b4a38907f5dcaa08e2ec115bac90
MD5 fa4de95ec9785240f8852fc06da6df9a
BLAKE2b-256 738dbed6bfb39121b004072f96b2547e3cddd6521b3ceca6f7bcf9d4dfd998ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonlite-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4be364bbbf28a300a0043d2019d8f434379dcbad0f5c74f32dae41beda3a6e03
MD5 b5e59ec97c28627d9373d5583c8ba3b5
BLAKE2b-256 bbbd056e0b48d6329694ddb1b4d78cf4450d3dece52095ce1efea7c2c428705b

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