Skip to main content

A lightweight, relational database built from scratch in Python

Project description

YesDB

A lightweight relational database built from scratch in Python with SQL support, B-tree storage, and a cloud Backend-as-a-Service for students.

Installation

# Local only
pip install yesdb

# With cloud support
pip install yesdb[cloud]

Quick Start

Local Mode

from yesdb import connect

db = connect("myapp.db")
db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
db.execute("INSERT INTO users VALUES (NULL, 'Alice', 30)")
results = db.execute("SELECT * FROM users")
for row in results:
    print(row)
db.close()

Cloud Mode

YesDB Cloud lets you host your database on a remote server. Perfect for student projects that need a real backend.

1. Sign up and create a database

yesdb signup
# Email: student@uni.edu
# Password: ********
# -> Account created! Logged in.

yesdb init myproject
# -> Created yesdb/ folder with schema.py
# -> Database "myproject" created on cloud.

2. Define your schema

After running yesdb init, you'll have a yesdb/schema.py file in your project. Edit it:

# yesdb/schema.py
from yesdb import Table, Column, Integer, Text, Real

users = Table("users", [
    Column("id", Integer, primary_key=True),
    Column("name", Text),
    Column("email", Text),
])

products = Table("products", [
    Column("id", Integer, primary_key=True),
    Column("name", Text),
    Column("price", Real),
])

3. Push your schema to the cloud

yesdb push
# -> Connecting to myproject database...
# -> Table "users" created
# -> Table "products" created
# -> Schema synced. 2 tables pushed.

4. Use in your code

from yesdb import connect

db = connect("myproject")  # uses saved credentials automatically

db.execute("INSERT INTO users VALUES (NULL, 'Alice', 'alice@uni.edu')")
db.execute("INSERT INTO users VALUES (NULL, 'Bob', 'bob@uni.edu')")

rows = db.execute("SELECT * FROM users")
for row in rows:
    print(row)

Every response includes the database engine's internal logs (B-tree operations, SQL parsing, page allocations), so you can see exactly what's happening under the hood.

5. Use with FastAPI or Flask

# main.py
from fastapi import FastAPI
from yesdb import connect

app = FastAPI()
db = connect("myproject")

@app.get("/users")
def get_users():
    rows = db.execute("SELECT * FROM users")
    return {"users": [list(row) for row in rows]}

@app.post("/users")
def create_user(name: str, email: str):
    db.execute(f"INSERT INTO users VALUES (NULL, '{name}', '{email}')")
    return {"status": "created"}

CLI Commands

yesdb signup              # Create an account
yesdb login               # Login to existing account
yesdb init <db_name>      # Initialize a project with a cloud database
yesdb push                # Push schema.py to the cloud
yesdb databases           # List your databases
yesdb shell <db_name>     # Interactive SQL shell against a cloud database

Local CLI Shell

yesdb-local mydatabase.db
YesDB> CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER);
YesDB> INSERT INTO users VALUES (NULL, 'Alice', 30);
YesDB> SELECT * FROM users;
.help          Show help
.tables        List all tables
.schema        Show table schemas
.exit          Exit shell

Features

  • SQL Support: CREATE, SELECT, INSERT, UPDATE, DELETE, DROP, ALTER TABLE
  • Data Types: INTEGER, TEXT, REAL, BLOB
  • Query Features: WHERE, ORDER BY, LIMIT, OFFSET, DISTINCT
  • B-Tree Storage: Efficient indexing and data retrieval
  • No Dependencies: Pure Python implementation (local mode)
  • Cloud BaaS: Host your database remotely with a single command
  • Schema DSL: Define tables in Python, push to cloud
  • Engine Logs: See B-tree splits, page allocations, and SQL parsing in every response
  • Interactive Shell: Built-in SQL shell (local and cloud)
  • Auto-increment: PRIMARY KEY auto-increment support

SQL Examples

-- Create table
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT, age INTEGER)

-- Insert data
INSERT INTO users VALUES (NULL, 'Alice', 'alice@example.com', 30)
INSERT INTO users VALUES (NULL, 'Bob', 'bob@example.com', 25)

-- Query with conditions
SELECT * FROM users WHERE age > 25
SELECT name, email FROM users WHERE name = 'Alice'

-- Order and limit
SELECT * FROM users ORDER BY age DESC
SELECT * FROM users LIMIT 10 OFFSET 5

-- Update and delete
UPDATE users SET age = 31 WHERE name = 'Alice'
DELETE FROM users WHERE age < 18

-- Alter table
ALTER TABLE users ADD COLUMN country TEXT

-- Drop table
DROP TABLE users

How Cloud Mode Works

Your machine                   YesDB Cloud Server
────────────────               ──────────────────
yesdb CLI (signup/login/push)   ┌─────────────────┐
   <-> HTTPS                    │ nginx (SSL)      │
yesdb SDK (connect/execute)     │  └─ FastAPI      │
                                │     ├─ auth      │
                                │     └─ data/     │
                                │       ├─ user1/  │
                                │       │  └─ *.db │
                                │       └─ user2/  │
                                │          └─ *.db │
                                └─────────────────┘
  • Each user gets their own isolated account with multiple databases
  • All traffic is encrypted over HTTPS
  • Authentication via API key (generated at signup, saved locally)
  • Database engine logs are returned with every query for full transparency

Security

Local Mode

  • Path validation (blocks system file access)
  • Resource limits (SQL length, record size)
  • Input validation (table/column names)

Cloud Mode

  • HTTPS encryption (TLS via Let's Encrypt)
  • API key authentication (SHA-256 hashed, never stored in plaintext)
  • Password hashing (bcrypt)
  • Per-user data isolation
  • Request size limits

Development

Install from Source

git clone https://github.com/AzharAhmed-bot/yesdb.git
cd yes_db
pip install -e ".[cloud]"

Run Tests

pip install pytest
pytest

Requirements

  • Python 3.8+
  • No external dependencies (local mode)
  • requests (cloud mode, installed with pip install yesdb[cloud])

License

MIT License - see LICENSE file

Links

Version

Current version: 0.1.3


Note: YesDB is an educational database built from scratch to teach database internals. For production systems, consider SQLite, PostgreSQL, or MySQL.

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

yesdb-0.1.4.tar.gz (78.0 kB view details)

Uploaded Source

Built Distribution

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

yesdb-0.1.4-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file yesdb-0.1.4.tar.gz.

File metadata

  • Download URL: yesdb-0.1.4.tar.gz
  • Upload date:
  • Size: 78.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for yesdb-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6c6ab05cbf4669e16ebc8f1995b52f3941b382bb6b2a471e8efb246f71797b6f
MD5 6f41619a35cfd437e407697fe96ad746
BLAKE2b-256 0b11fd7e242e2f3c94c458ada0b2800ddb0904f0715613c2a3d90f16d1fd52c2

See more details on using hashes here.

File details

Details for the file yesdb-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: yesdb-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 52.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for yesdb-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 72ac4fe8403ecb1e6e661e5d4eedc33885220d3d5351b73bef761cded1dd7718
MD5 87e2081a8515ed1462225cfab323a53e
BLAKE2b-256 2a4e133d4422f5b1231427a584ff8187e635f9f0da538fa62dc4abf94ff1e3d2

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