Skip to main content

What is this?

LightDB is a simple and lightweight JSON database for Python that allows users to efficiently write data to a file. It is designed to be easy to use, making it a great choice for developers who need a fast and reliable way to store and retrieve data

Features

  • Lightweight and Simple: LightDB is a lightweight database implemented as a Python dictionary with an intuitive API for easy key-value management

  • JSON Storage and Persistence: Data is stored and retained in a JSON file, allowing easy external editing and persistence between runs

  • Reset Capability: Provides a reset method to clear the database and start fresh

  • Type Agnostic: Can store any Python object as a value

  • Portable: Easily transferable between systems, ideal for simple data storage

  • Model Support: Supports models for structured data management, ensuring organized and maintainable code

Installing

You can install LightDB using pip:

pip install LightDB

Usage

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("db.json")

You can then set key-value pairs in the database using the set() method:

db.set("name", "Alice")
db.set("age", 30)

To save the changes, use the save() method:

db.save()

Using Models

LightDB supports defining models for more structured and convenient data management. Here’s how to use models with LightDB:

First, import the necessary classes:

from typing import List, Dict, Any

from lightdb import LightDB
from lightdb.models import Model

Define your model by extending the Model class:

class User(Model, table="users"):
    name: str
    age: int
    items: List[str] = []
    extra: Dict[str, Any] = {}

Create a new instance of the model and save it to the database:

user = User.create(name="Alice", age=30)

Retrieve a user from the database:

user = User.get(User.name == "Alice")
# or user = User.get(name="Alice")
print(user.name, user.age)

Update a user’s information and save it:

user.name = "Kristy"
user.save()

Filter users based on certain criteria:

users = User.filter(User.age >= 20)
for user in users:
    print(user.name)

Delete a user:

user.delete()

Metadata

Release files for LightDB 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LightDB 2.0
File Size Uploaded
LightDB-2.0.tar.gz 7.4 kB Details

Release files / LightDB-2.0.tar.gz

Download URL LightDB-2.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e4ff4054e871cfca81bda1cb59561367fa9edba7512806f1ecf81fcc8f125e3f
BLAKE2b-256 checksum
How to use checksums
1f530b89ef568d7cbc4fe184de7593841433c33005c12ecab80743a758bb5e33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

2.0 This release

1 release file

1.4.0

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3

1 release file

1.2

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page