Skip to main content

A lightweight, schema-aware, CSV-based database with auto-increment IDs

Project description

๐Ÿ‹ LemonDB

A lightweight, schema-aware database in Python

Python License CSV

Simple โ€ข Fast โ€ข Readable โ€ข Perfect for Small Projects

Features โ€ข Quick Start โ€ข Documentation โ€ข Examples


๐ŸŒŸ Features

  • ๐ŸŽฏ Schema Validation - Define types and constraints (required, unique)
  • ๐Ÿ“ Simple API - Intuitive CRUD operations
  • ๐Ÿ“ฆ CSV Storage - Human-readable files, no external database
  • ๐Ÿ” Easy Queries - Find records with simple dict queries
  • ๐Ÿ‹ Helpful Logging - All operations log with lemon icons
  • ๐Ÿ“‚ Custom Paths - Store databases anywhere you want
  • โšก Zero Dependencies - Uses only Python standard library

๐Ÿš€ Quick Start

Installation

pip install lemonDB

Basic Example

from app import LemonDB

# 1. Define schema
schema = {
    "username": "string",
    "email": "string",
    "age": "integer"
}

# 2. Create database
db = LemonDB(name="users", schema=schema)
# ๐Ÿ‹ Schema 'users' was created

# 3. Save records (as tuples matching schema order)
db.save(
    ("alice", "alice@example.com", 25),
    ("bob", "bob@example.com", 30)
)
# ๐Ÿ‹ Saved 2 record(s) to 'users'

# 4. Query data
users = db.findAll()
print(users)
# [{'username': 'alice', 'email': 'alice@example.com', 'age': 25}, ...]

# 5. Find specific records
alice = db.find({"username": "alice"})

# 6. Update
db.updateOne({"username": "alice"}, {"age": 26})
# ๐Ÿ‹ Updated 1 record in 'users'

# 7. Delete
db.deleteOne({"username": "bob"})
# ๐Ÿ‹ Deleted 1 record from 'users'

๐Ÿ“– Schema Definition

Simple Schema

schema = {
    "name": "string",
    "age": "integer",
    "score": "float",
    "active": "boolean",
    "joined": "date"
}

Supported Types: string, integer, float, boolean, date

Advanced Schema with Constraints

schema = {
    "id": {"type": "integer", "required": True, "unique": True},
    "email": {"type": "string", "required": True, "unique": True},
    "name": {"type": "string", "required": True},
    "active": {"type": "boolean"}
}

Constraints:

  • required: True - Field cannot be empty or None
  • unique: True - Field must be unique across all records

๐Ÿ’ก Examples

Example 1: Todo List

from app import LemonDB

schema = {
    "id": {"type": "integer", "required": True, "unique": True},
    "task": {"type": "string", "required": True},
    "done": {"type": "boolean"}
}

todos = LemonDB("todos", schema=schema)

# Add tasks
todos.save(
    (1, "Buy groceries", False),
    (2, "Learn Python", False),
    (3, "Exercise", False)
)

# Mark as done
todos.updateOne({"id": 2}, {"done": True})

# Find incomplete tasks
incomplete = todos.find({"done": False})
print(f"You have {len(incomplete)} tasks left!")

Example 2: Custom Storage Path

# Store in custom location
db = LemonDB(
    name="products",
    schema={"name": "string", "price": "float"},
    data_dir="/path/to/my/data"
)

db.save(("Laptop", 999.99), ("Mouse", 25.50))
# Files created at: /path/to/my/data/products.csv

Example 3: Multiple Databases

# User database
users_db = LemonDB("users", schema={"name": "string", "email": "string"})

# Products database
products_db = LemonDB(
    "products",
    schema={"name": "string", "price": "float", "stock": "integer"},
    data_dir="./inventory"
)

# Activity logs
logs_db = LemonDB(
    "logs",
    schema={"timestamp": "string", "action": "string"},
    data_dir="/var/logs"
)

๐Ÿ“š API Reference

Method Description Example
save(*records) Save one or more records db.save(("Alice", 25))
findAll() Get all records db.findAll()
find(query) Query records db.find({"age": 25})
deleteOne(query) Delete first match db.deleteOne({"name": "Alice"})
deleteAll() Delete all records db.deleteAll()
updateOne(query, data) Update first match db.updateOne({"id": 1}, {"age": 26})
count() Count records db.count()
test() Test database status db.test()

Full Documentation โ†’


๐Ÿ“‚ Project Structure

lemonDB/
โ”œโ”€โ”€ README.md                    # This file
โ”œโ”€โ”€ docs.md                      # Full documentation
โ”œโ”€โ”€ LICENSE                      # MIT License
โ”œโ”€โ”€ setup.py                     # Package setup
โ”œโ”€โ”€ requirements.txt             # Dependencies
โ”œโ”€โ”€ .gitignore                   # Git ignore rules
โ”‚
โ”œโ”€โ”€ app/                         # Main package
โ”‚   โ”œโ”€โ”€ __init__.py             # Package init
โ”‚   โ”œโ”€โ”€ core.py                 # LemonDB main class
โ”‚   โ”œโ”€โ”€ schema.py               # Schema validation
โ”‚   โ”œโ”€โ”€ engine.py               # CSV storage engine
โ”‚   โ””โ”€โ”€ utils.py                # Helper utilities
โ”‚
โ”œโ”€โ”€ tests/                       # Test files
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_creation.py        # Test db creation
โ”‚   โ”œโ”€โ”€ test_count.py           # Test count function
โ”‚   โ””โ”€โ”€ test_db_test.py         # Test db.test() method
โ”‚
โ””โ”€โ”€ examples/                    # Usage examples
    โ”œโ”€โ”€ example_save.py         # Save operations
    โ”œโ”€โ”€ example_find.py         # Query operations
    โ”œโ”€โ”€ example_update.py       # Update operations
    โ”œโ”€โ”€ example_delete.py       # Delete operations
    โ””โ”€โ”€ todo_app.py             # Complete todo app

Running Tests

# Test database creation
python3 -m tests.test_creation

# Test count function
python3 -m tests.test_count

# Test db.test() method
python3 -m tests.test_db_test

Running Examples

# Save operations
python3 -m examples.example_save

# Find/query operations
python3 -m examples.example_find

# Update operations
python3 -m examples.example_update

# Delete operations
python3 -m examples.example_delete

# Complete todo app
python3 -m examples.todo_app
lemondb_data/
โ”œโ”€โ”€ users.csv                  # Your data
โ”œโ”€โ”€ users_metadata.json        # Schema definition
โ”œโ”€โ”€ products.csv
โ””โ”€โ”€ products_metadata.json

Example CSV:

username,email,age
alice,alice@example.com,25
bob,bob@example.com,30

๐ŸŽฏ Use Cases

โœ… Perfect for:

  • Small to medium projects (< 10K records)
  • Prototypes and MVPs
  • Configuration storage
  • Learning database concepts
  • Simple data persistence

โš ๏ธ Not suitable for:

  • Large datasets (no indexing)
  • Concurrent access (no locking)
  • Production systems requiring high performance

๐Ÿ”ง Advanced Features

Error Handling

# Skip invalid records instead of raising errors
db.save(
    ("Alice", "alice@test.com"),
    ("Bob", None),  # Missing required field
    ("Charlie", "charlie@test.com"),
    raise_on_error=False
)
# Skipping record ('Bob', None): Field 'email' is required
# ๐Ÿ‹ Saved 2 record(s) to 'users'

Database Testing

db.test()
# ๐Ÿ‹ DB 'users' is created and working!
# ๐Ÿ‹ Current records: 5
# ๐Ÿ‹ Schema fields: username, email, age

๐Ÿ“Š Performance

  • Small datasets (< 1K records): โšก Instant
  • Medium datasets (1K - 10K records): ๐Ÿƒ Fast
  • Large datasets (> 10K records): ๐ŸŒ Slower (uses full table scans)

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • ๐Ÿ› Report bugs
  • ๐Ÿ’ก Suggest features
  • ๐Ÿ”ง Submit pull requests

๐Ÿ“„ License

MIT License - Use freely in your projects!


โฌ† Back to Top

Made with โค๏ธ and ๐Ÿ‹

Features

  • CSV-Based Storage: No external database required
  • Simple API: Intuitive methods like save(), deleteOne(), deleteAll(), find(), etc.
  • Schema Definition: Define your data structure upfront
  • Easy Installation: Install via pip install lemonDB
  • Minimal Dependencies: Keep it lightweight and fast

Installation

pip install lemonDB

Quick Start

1. Define Your Schema

Create a schema that describes your data structure:

from lemondb import LemonDB

# Define your schema (simple dictionary format)
schema = {
    "name": "string",
    "email": "string",
    "age": "integer",
    "active": "boolean"
}

2. Initialize Your Database

# Create a LemonDB instance
db = LemonDB(name="myapp", engine="csv", schema=schema)

3. Save Data

# Create a record matching your schema
user1 = ["Anna", "anna@example.com", 25, True]

# Save it
db.save(user1)

4. Query Data

# Find records
results = db.find({"name": "Anna"})

# Find all
all_users = db.findAll()

# Delete one record
db.deleteOne({"name": "Anna"})

# Delete all records
db.deleteAll()

# Update records
db.updateOne({"name": "Anna"}, {"age": 26})

# Get count
count = db.count()

Schema Format

Supported data types:

schema = {
    "fieldName": "string",      # Text data
    "age": "integer",            # Whole numbers
    "salary": "float",           # Decimal numbers
    "active": "boolean",         # True/False
    "joined": "date"             # YYYY-MM-DD format
}

Folder Structure

lemonDB/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ lemondb/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ core.py                  # Main LemonDB class
โ”‚   โ”œโ”€โ”€ schema.py                # Schema validation
โ”‚   โ”œโ”€โ”€ engine.py                # CSV engine
โ”‚   โ””โ”€โ”€ utils.py                 # Helper functions
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_save.py
โ”‚   โ”œโ”€โ”€ test_query.py
โ”‚   โ””โ”€โ”€ test_delete.py
โ””โ”€โ”€ examples/
    โ”œโ”€โ”€ basic_usage.py
    โ”œโ”€โ”€ user_database.py
    โ””โ”€โ”€ todo_app.py

Example Usage

Create a User Database

from lemondb import LemonDB

# Define schema
user_schema = {
    "username": "string",
    "email": "string",
    "age": "integer",
    "premium": "boolean"
}

# Initialize
db = LemonDB(name="users", engine="csv", schema=user_schema)

# Add users
user1 = ["anna_teku", "anna@example.com", 25, True]
user2 = ["john_doe", "john@example.com", 30, False]

db.save(user1)
db.save(user2)

# Query
all_users = db.findAll()
premium_users = db.find({"premium": True})

# Delete
db.deleteOne({"username": "john_doe"})

API Reference

Core Methods

  • save(record) - Insert a new record
  • findAll() - Retrieve all records
  • find(query) - Find records matching query
  • deleteOne(query) - Delete first matching record
  • deleteAll() - Delete all records
  • updateOne(query, data) - Update first matching record
  • updateAll(query, data) - Update all matching records
  • count() - Get total record count

Data Storage

Your data is stored as CSV files in a lemondb_data/ directory:

lemondb_data/
โ”œโ”€โ”€ myapp.csv          # Your database file
โ””โ”€โ”€ myapp_metadata.json # Schema and metadata

Why LemonDB?

โœจ Minimal Setup - No database server needed
โœจ Human Readable - CSV files you can open and read
โœจ Perfect for Small Projects - Prototypes, scripts, small apps
โœจ Lightweight - Minimal dependencies

Limitations

  • Best suited for small datasets (< 50K records)
  • Single file operations (not optimized for concurrent access)
  • No complex joins or transactions

Contributing

Contributions welcome! Feel free to submit issues and pull requests.

License

MIT License - feel free to use in your projects!


Happy coding! ๐Ÿ‹

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

lemodb_foxerbn-1.0.0.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

lemodb_foxerbn-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file lemodb_foxerbn-1.0.0.tar.gz.

File metadata

  • Download URL: lemodb_foxerbn-1.0.0.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for lemodb_foxerbn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ed7f5e4824725745bbebafefadf4ebc96decf6548b089cac2e33e1a30d167650
MD5 217a53d44f5895decc7ad98ec6a730ba
BLAKE2b-256 3ce40265d28f7e63ffba150620fc87b63908c2472760f82e93ca0af8a08ec7e4

See more details on using hashes here.

File details

Details for the file lemodb_foxerbn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lemodb_foxerbn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for lemodb_foxerbn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17a51d697a0fbe8bf015bd18d88b8b1676ff10b2b6912961c1494a61cb3d9be8
MD5 e2c4c0d306125c7a69a27ed798c15a23
BLAKE2b-256 8332b0ffc61aecaf65ce18f9960a1b4b45d85b7464d46fb3e7e7bf88b04a9775

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