Skip to main content

A lightweight Python database engine that stores JSON-like records with optional encryption support.

Project description

PyLiteDB

PyLiteDB is a small, lightweight database engine written in Python. It stores data as JSON-like records. You can store, update, get, and delete records in tables. It also supports optional encryption to keep your data safe.

Features:

  • Create tables and store JSON-like data

  • Insert, update, delete, and fetch records by ID

  • Get all records from a table

  • Filter records using a key and value

  • Optional AES-GCM encryption with SHA3-based keys

  • A salt file (.salt) is used to help with encryption and decryption

  • Write-Ahead Logging (WAL) for crash-safe operations

  • Metadata stored in .meta.json files

  • Includes an easy-to-use CLI mode for managing databases

Installation:

Ensure that Python 3.10 or newer is installed on your system.

You can install PyLiteDB using pip or pip3:

pip3 install pylitedb-engine
# or
pip install pylitedb-engine

Usage Example

from PyLiteDB import Database

# Create or open database with optional passphrase
db = Database("test.db", "mypassword")

# Create a table
db.create_table("users")

# Insert records
uid1 = db.insert("users", {"name": "Sreeraj", "age": 21})
uid2 = db.insert("users", {"name": "Sreereshmi", "age": 17})
uid3 = db.insert("users", {"name": "Alex", "age": 25})

# Fetch a record by ID
record = db.get("users", uid1)
print("Single record:", record)

# Access single pieces of data from the record
print("Name:", record["name"])
print("Age:", record["age"])

# Update a record
# You can change existing fields or add new ones
db.update("users", uid1, {
    "name": "Sreekuttan",
    "role": "developer",
    "email": "sreekuttan@example.com"
})

# Fetch the updated record to confirm changes
updated_record = db.get("users", uid1)
print("\nUpdated record:", updated_record)

# Delete a record
db.delete("users", uid2)

# Fetch all records
all_records = db.find_all("users")
print("\nAll records:", all_records)

# Filter records by key/value
filtered = db.find_by_filter("users", "name", "Alex")
print("\nFiltered (name='Alex'):", filtered)

# Accessing filtered data
if filtered:
    # Print entire row of filtered data
    print("\nFiltered row:", filtered)
    
    # Print single pieces of data from filtered
    print("Filtered name:", filtered[0]["name"])
    print("Filtered age:", filtered[0]["age"])

# Commit changes
db.commit()

File Structure:

test.db           # Stores the main database data
test.meta.json    # Stores table metadata
test.db.wal       # Write-Ahead Log for crash recovery
test.salt         # Stores the cryptographic salt used for encryption

Usage(CLI Mode)

You can start the interactive PyLiteDB shell using:

python3 -m PyLiteDB

This command will open the PyLiteDB shell with a new or existing database named pylitedb.db (unencrypted by default).

If you want to use a specific database file with encryption enabled, provide a passphrase:

python3 -m PyLiteDB mydatabase.db mysecret

If the database file (mydatabase.db) does not exist, it will be created automatically.

If the file already exists, the same passphrase used during creation must be provided to access it.

If no passphrase is provided, the database will operate in unencrypted mode.

Once started, you’ll see the prompt:

pylite>

Supported CLI Commands

Command Description
CREATE TABLE <name> Create a new table in the database.
INSERT INTO <table> VALUES <json> Insert a JSON-formatted record into the specified table.
SELECT * FROM <table> Display all records from the specified table.
UPDATE <table> <row_id> <json> Update the record with the given row ID in the specified table.
DELETE <table> <row_id> Delete the record with the given row ID from the specified table.
FILTER <table> <key>=<value> Display records where the given key matches the specified value.
EXIT or QUIT Exit the PyLiteDB interactive shell.

Example Session

pylite> CREATE TABLE users
Created table 'users'
pylite> INSERT INTO users VALUES{"name":"sreeraj","age":21}
Inserted row ID: c75ad045fbd449be9591ddab93fe204a
pylite> SELECT * FROM users
{'name': 'sreeraj', 'age': 21}
pylite> UPDATE users c75ad045fbd449be9591ddab93fe204a {"name":"sreereshmi","age":17}
Updated successfully
pylite> SELECT * FROM users
{'name': 'sreereshmi', 'age': 17}
pylite> UPDATE users c75ad045fbd449be9591ddab93fe204a {"name":"sreeraj","age":21,"role":"developer"}
Updated successfully
pylite> SELECT * FROM users
{'name': 'sreeraj', 'age': 21, 'role': 'developer'}
pylite> FILTER users name=sreeraj
{'name': 'sreeraj', 'age': 21, 'role': 'developer'}
pylite> DELETE users c75ad045fbd449be9591ddab93fe204a
Deleted successfully
pylite> SELECT * FROM users
pylite> EXIT

Using the CLI Programmatically (Inside a Python Script)

You can also run the PyLiteDB CLI directly from a Python file by importing it:

from PyLiteDB.cli import main

# Example 1: Run with the default database (unencrypted)
main([])

# Example 2: Run with a specific database file (unencrypted)
main(["mydatabase.db"])

# Example 3: Run with encryption using a passphrase
main(["mydatabase.db", "mysecret"])

This is useful when you want to embed the interactive PyLiteDB shell inside another Python-based project or provide a scripted interface for database management.

Notes:

  • Always use the Database API, do not edit .db, .meta.json or .salt manually.

  • Encryption works only if you provide a passphrase.

License

This project is licensed under the MIT License

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

pylitedb_engine-1.0.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylitedb_engine-1.0.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file pylitedb_engine-1.0.1.tar.gz.

File metadata

  • Download URL: pylitedb_engine-1.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pylitedb_engine-1.0.1.tar.gz
Algorithm Hash digest
SHA256 717df6c20624689b75d624367ee2981bacc332937c380b26f1043733c79bbbf8
MD5 794956d013f2c7c5b089fa5238721b03
BLAKE2b-256 c4892dae2a0fbbab431390002b28d81547d3681d2b182dd0be64f57dafa85b82

See more details on using hashes here.

File details

Details for the file pylitedb_engine-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pylitedb_engine-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce2092f033c8d4eb759ffa1c91ea2040ef32b52af27e0b9e472b5f67b7064115
MD5 a6035331ae1523af5462eb8c6a17e7a7
BLAKE2b-256 06d0f8a268cd17ad6674ecd2e051ebd22f40181a75a56c8a33bc9c33fb254406

See more details on using hashes here.

Supported by

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