A Python-native object database
Project description
YourDB
YourDB is a lightweight, Python-native object database designed to persist and query Python objects with schema validation and SQL-like querying capabilities.
It allows developers to define entities using Python dictionaries (or class-like schemas), insert objects, and perform filtering, updating, or deleting โ all using native Python.
๐ Features
- ๐งฑ Define custom entities with schema validation
- ๐ฆ Store any Python dictionary or object (pickle-backed)
- ๐ง Functional querying with lambda conditions
- ๐ Update & delete data using custom logic
- ๐พ Persistent storage using
pickleunder the hood - ๐ Future extensibility for SQL-like syntax and class-based schemas
๐ฆ Installation
git clone https://github.com/Dhruv251004/yourdb
cd yourdb
pip install .
๐ Quickstart
# 1. Import the necessary components from yourdb
from yourdb import YourDB, register_class
# 2. Define your data model as a standard Python class
# The @register_class decorator is essential for the database to handle your object.
@register_class
class User:
def __init__(self, user_id, name, city, is_active=True):
self.user_id = user_id
self.name = name
self.city = city
self.is_active = is_active
def __repr__(self):
# A nice string representation for printing the object
return f"User(id={self.user_id}, name='{self.name}', city='{self.city}', active={self.is_active})"
# 3. Initialize the database (this will create a 'my_app.yourdb' directory)
db = YourDB("my_app")
# 4. Define a schema for your entity, including which fields to index
user_schema = {
'primary_key': 'user_id',
'user_id': "int",
'name': "str",
'city': "str",
'is_active': "bool",
'indexes': ['city'] # We'll create an index on the 'city' field for fast lookups
}
# 5. Create an entity (similar to a table)
db.create_entity("users", user_schema)
# 6. Insert your custom objects directly (no .to_dict() needed)
print("--> Inserting 3 users...")
db.insert_into("users", User(user_id=101, name="Alice", city="New York"))
db.insert_into("users", User(user_id=102, name="Bob", city="London"))
db.insert_into("users", User(user_id=103, name="Charlie", city="New York"))
# 7. Query data using an index for high performance
print("\n--> Fetching users from 'New York' (uses the 'city' index)...")
ny_users = db.select_from("users", filter_dict={'city': 'New York'})
print(ny_users)
# 8. Update data using a filter dictionary
print("\n--> Deactivating Bob...")
def deactivate_user(user):
user.is_active = False
return user
# The update operation will use a full scan because 'name' is not indexed
db.update_entity("users", filter_dict={'name': 'Bob'}, update_fn=deactivate_user)
# Verify the update by fetching the record again
bob = db.select_from("users", filter_dict={'user_id': 102})[0]
print(f"Verified update: {bob}")
# 9. Delete data using a filter
print("\n--> Deleting user 101...")
db.delete_from("users", filter_dict={'user_id': 101})
# Verify the deletion by fetching all remaining users
all_users = db.select_from("users")
print(f"Final users in DB: {all_users}")
๐ Directory Structure
yourdb/
โโโ .gitignore
โโโ LICENSE
โโโ MANIFEST.in
โโโ pyproject.toml # Project configuration (replaces requirements.txt)
โโโ Readme.md
โ
โโโ test_files/ # Contains benchmark and test scripts
โ โโโ fetch_test.py
โ โโโ main.py
โ
โโโ yourdb/ # The core source code of the database package
โโโ __init__.py # Makes 'yourdb' a Python package
โโโ compaction.py # Handles log file compaction logic
โโโ entity.py # Core storage engine and entity-level logic
โโโ utils.py # Serialization, validation, and helper functions
โโโ yourdb.py # Main public API and DB interface
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 yourdb-0.1.1.tar.gz.
File metadata
- Download URL: yourdb-0.1.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
572ca5cfbeb12b95da586f2668954b1718d86f20b6ceda0e79d942539bb83aca
|
|
| MD5 |
8ecc31ff91ecd77c06dbf9a85648d579
|
|
| BLAKE2b-256 |
5f903d796b7ca4b02567a3324ad36715c13de5e0c603e5ac801e84af75410f2b
|
File details
Details for the file yourdb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: yourdb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4e8130cd5beeb2e8d0b793f064e74846502f0b060a59b8e7880ddf08f1497d1
|
|
| MD5 |
a8891a9acd2a60d6a9792a209eb5e4d7
|
|
| BLAKE2b-256 |
ba59bb52299480836eb11e1f19dd0a6b3674bdf8d2f6e32e87fdc16a48aaae8d
|