A lightweight, schema-aware, CSV-based database with auto-increment IDs
Project description
๐ LemonDB
A lightweight, schema-aware database in Python
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 Noneunique: 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() |
๐ 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!
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 recordfindAll()- Retrieve all recordsfind(query)- Find records matching querydeleteOne(query)- Delete first matching recorddeleteAll()- Delete all recordsupdateOne(query, data)- Update first matching recordupdateAll(query, data)- Update all matching recordscount()- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed7f5e4824725745bbebafefadf4ebc96decf6548b089cac2e33e1a30d167650
|
|
| MD5 |
217a53d44f5895decc7ad98ec6a730ba
|
|
| BLAKE2b-256 |
3ce40265d28f7e63ffba150620fc87b63908c2472760f82e93ca0af8a08ec7e4
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17a51d697a0fbe8bf015bd18d88b8b1676ff10b2b6912961c1494a61cb3d9be8
|
|
| MD5 |
e2c4c0d306125c7a69a27ed798c15a23
|
|
| BLAKE2b-256 |
8332b0ffc61aecaf65ce18f9960a1b4b45d85b7464d46fb3e7e7bf88b04a9775
|