Skip to main content

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

>>> # Initialize the database
>>> db = JSONlite('mydatabase.json')

>>> # Inserting one document
>>> result = db.insert_one({"name": "John Doe", "age": 30})
>>> result.inserted_id
1

>>> # Inserting multiple documents
>>> result = db.insert_many([
...     {"name": "Jane Doe", "age": 25},
...     {"name": "Alice", "age": 28}
... ])
>>> result.inserted_ids
[2, 3]

>>> # Finding one document
>>> document = db.find_one({"name": "John Doe"})
>>> document
{'_id': 1, 'name': 'John Doe', 'age': 30}

>>> # Finding multiple documents
>>> documents = db.find({"age": {"$gte": 25}})
>>> documents
[
    {'_id': 1, 'name': 'John Doe', 'age': 30},
    {'_id': 2, 'name': 'Jane Doe', 'age': 25},
    {'_id': 3, 'name': 'Alice', 'age': 28}
]

>>> # Updating one document
>>> result = db.update_one({"name": "John Doe"}, {"$set": {"age": 31}})
>>> result.matched_count, result.modified_count
(1, 1)

>>> # Updating multiple documents
>>> result = db.update_many({"age": {"$gte": 25}}, {"$set": {"status": "active"}})
>>> result.matched_count, result.modified_count
(3, 3)

>>> # Deleting one document
>>> result = db.delete_one({"name": "John Doe"})
>>> result.deleted_count
1

>>> # Deleting multiple documents
>>> result = db.delete_many({"age": {"$lt": 30}})
>>> result.deleted_count
2

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonlite-0.0.5.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

Hashes for jsonlite-0.0.5.tar.gz
Algorithm Hash digest
SHA256 424562c015c07113f3d1287c4e18756d49f718b93d91c7c19875c8a46e5f8176
MD5 f96aab269ddaf4e7eb4563aebed2acc8
BLAKE2b-256 0bccd1c0f7b1d6168462f0a273367cc0bc3450e83ee6561700706db4987ffa59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonlite-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 19dc359671b1da960abbd2dee020d97b171fcef54c99f7c9f008c3cede467065
MD5 064f80fe3d5324df1cadc4cd35a4ddb8
BLAKE2b-256 46bcc8586ea5f63771e54343b25afafe23226e4616831d9abf02f41a66318988

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