Skip to main content

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 pickle under 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yourdb-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

yourdb-0.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

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

Hashes for yourdb-0.1.1.tar.gz
Algorithm Hash digest
SHA256 572ca5cfbeb12b95da586f2668954b1718d86f20b6ceda0e79d942539bb83aca
MD5 8ecc31ff91ecd77c06dbf9a85648d579
BLAKE2b-256 5f903d796b7ca4b02567a3324ad36715c13de5e0c603e5ac801e84af75410f2b

See more details on using hashes here.

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

Hashes for yourdb-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4e8130cd5beeb2e8d0b793f064e74846502f0b060a59b8e7880ddf08f1497d1
MD5 a8891a9acd2a60d6a9792a209eb5e4d7
BLAKE2b-256 ba59bb52299480836eb11e1f19dd0a6b3674bdf8d2f6e32e87fdc16a48aaae8d

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