A production-ready hybrid database system combining SQL and NoSQL with enterprise features
Project description
๐๏ธ PyHybridDB - Hybrid Database System
A Python-based hybrid database system combining SQL and NoSQL paradigms with a modern web-based admin panel
๐ Table of Contents
- Features
- Quick Start
- Installation
- Usage
- Authentication
- Configuration
- API Documentation
- CLI Commands
- Examples
- Project Structure
- Testing
- Security
- License
โจ Features
Core Features
- ๐ Hybrid Data Model - SQL tables + NoSQL collections in one database
- ๐พ Custom Storage Engine - Efficient
.phdbfile format with B-Tree indexing - ๐ Unified Query Language - Execute both SQL and MongoDB-style queries
- ๐ REST API - Complete FastAPI backend with auto-generated docs
- ๐จ Web Admin Panel - Beautiful, responsive UI for database management
- ๐ JWT Authentication - Secure token-based authentication
- ๐ Role-Based Access Control - Admin, user, and readonly roles
- ๐ Real-time Statistics - Dashboard with database metrics
- ๐ ACID Transactions - Transaction support with commit/rollback
- ๐ฆ Import/Export - JSON and CSV format support
Advanced Features โจ NEW!
- ๐พ Backup & Restore - Automated backup with compression and rotation
- ๐ Audit Logging - Complete activity tracking and compliance
- ๐ฅ User Management - Full CRUD API for user administration
- ๐ JOIN Operations - INNER, LEFT, RIGHT, FULL OUTER joins
- ๐ Data Visualization - Charts and statistics generation
- ๐ PostgreSQL Migration - Import from PostgreSQL databases
- ๐ MongoDB Migration - Import from MongoDB collections
- ๐ Encrypted Storage - AES encryption for data at rest
Technical Features
- B-Tree indexing for fast lookups
- Block-based storage with checksums
- Transaction logging with ACID compliance
- Query caching and optimization
- CORS support with configurable origins
- Environment-based configuration
- Comprehensive error handling
- SQLite-based audit logging
- Automatic backup rotation
- Password-based encryption
๐ Quick Start
1. Installation
# Create virtual environment
python -m venv venv
# Activate virtual environment
.\venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install package
pip install -e .
2. Run Demo
python DEMO.py
3. Start Server
python -m pyhybriddb.cli serve
# Server runs at http://localhost:8000
# API docs at http://localhost:8000/docs
4. Open Admin Panel
Open admin/index.html in your web browser
Default Login:
- Username:
admin - Password:
admin123
๐ป Usage
Python API
from pyhybriddb import Database
# Create database
with Database(name="my_app", path="./data") as db:
# SQL-like tables
users = db.create_table("users", {
"name": "string",
"age": "integer",
"email": "string"
})
# Insert records
users.insert({"name": "Alice", "age": 30, "email": "alice@example.com"})
# Query records
all_users = users.select()
young_users = users.select(where={"age": 25})
# Update records
users.update(where={"name": "Alice"}, updates={"age": 31})
# NoSQL-like collections
posts = db.create_collection("posts")
# Insert documents
posts.insert_one({
"title": "Hello World",
"tags": ["intro", "hello"],
"author": {"name": "Alice"}
})
# Query documents
all_posts = posts.find()
alice_posts = posts.find({"author.name": "Alice"})
SQL Queries
from pyhybriddb.core.connection import Connection
with Database("my_db") as db:
conn = Connection(db)
# CREATE TABLE
conn.execute("CREATE TABLE products (name string, price float)")
# INSERT
conn.execute("INSERT INTO products (name, price) VALUES ('Laptop', 999.99)")
# SELECT
result = conn.execute("SELECT * FROM products WHERE price > 500")
# UPDATE
conn.execute("UPDATE products SET price = 899.99 WHERE name = 'Laptop'")
conn.commit()
NoSQL Queries
# MongoDB-style queries
conn.execute('db.posts.insertOne({"title": "Hello", "tags": ["intro"]})')
conn.execute('db.posts.find({"tags": "intro"})')
conn.execute('db.posts.updateOne({"title": "Hello"}, {"$set": {"views": 100}})')
conn.execute('db.posts.aggregate([{"$sort": {"views": -1}}, {"$limit": 10}])')
๐ Authentication
Overview
PyHybridDB uses JWT (JSON Web Token) authentication to secure the API and admin panel.
Default Credentials
- Username:
admin - Password:
admin123
โ ๏ธ IMPORTANT: Change these in production!
API Authentication
import requests
# Login
response = requests.post('http://localhost:8000/api/auth/login', json={
'username': 'admin',
'password': 'admin123'
})
data = response.json()
token = data['access_token']
# Use token for authenticated requests
headers = {'Authorization': f'Bearer {token}'}
response = requests.post(
'http://localhost:8000/api/databases',
json={'name': 'my_db'},
headers=headers
)
โ๏ธ Configuration
Environment Variables
PyHybridDB uses environment variables for configuration. After installing via pip, you can configure it in multiple ways:
Method 1: Create .env File (Recommended)
Create a .env file in your project directory:
# Create .env file
touch .env # Linux/Mac
# or
New-Item .env # Windows PowerShell
Add your configuration:
SECRET_KEY=your-super-secret-key-change-this
ADMIN_PASSWORD=your-secure-password
API_PORT=8000
DEFAULT_DB_PATH=./data
Method 2: Set Environment Variables
# Windows PowerShell
$env:SECRET_KEY = "my-secret-key"
$env:ADMIN_PASSWORD = "secure-password"
$env:API_PORT = "8080"
# Linux/Mac
export SECRET_KEY="my-secret-key"
export ADMIN_PASSWORD="secure-password"
export API_PORT="8080"
Method 3: Programmatic Configuration
import os
os.environ['SECRET_KEY'] = 'my-secret-key'
os.environ['DEFAULT_DB_PATH'] = './my_data'
from pyhybriddb import Database
db = Database("my_app")
Available Settings
# Security
SECRET_KEY=your-super-secret-key-change-this
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Admin Credentials
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin123
ADMIN_EMAIL=admin@pyhybriddb.com
# API Configuration
API_HOST=0.0.0.0
API_PORT=8000
# Database
DEFAULT_DB_PATH=./data
LOG_LEVEL=INFO
CORS_ORIGINS=*
View Configuration
python -m pyhybriddb.cli config
Generate Secure SECRET_KEY
import secrets
print(secrets.token_urlsafe(32))
๐ Advanced Features Usage
Backup & Restore
from pyhybriddb.utils.backup import BackupManager
backup_mgr = BackupManager()
# Create backup
backup_file = backup_mgr.create_backup("./data/my_db.phdb", compress=True)
# List backups
backups = backup_mgr.list_backups("my_db")
# Restore backup
restored = backup_mgr.restore_backup(backup_file)
# Auto-backup with rotation
backup_mgr.auto_backup("./data/my_db.phdb", max_backups=5)
Audit Logging
from pyhybriddb.utils.audit import get_audit_logger, AuditAction
audit = get_audit_logger()
# Log action
audit.log(
action=AuditAction.CREATE_DATABASE,
user="admin",
database_name="my_db",
success=True
)
# Get logs
logs = audit.get_logs(action=AuditAction.INSERT, limit=100)
# Get statistics
stats = audit.get_statistics()
JOIN Operations
from pyhybriddb.query.joins import JoinExecutor, JoinType
# Execute JOIN
result = JoinExecutor.execute_join(
left_table=users.select(),
right_table=orders.select(),
left_key="id",
right_key="user_id",
join_type=JoinType.INNER
)
PostgreSQL Migration
from pyhybriddb.migration import PostgreSQLMigration
from pyhybriddb import Database
# Connect to PostgreSQL
pg_migration = PostgreSQLMigration({
'host': 'localhost',
'port': 5432,
'database': 'mydb',
'user': 'postgres',
'password': 'password'
})
# Migrate to PyHybridDB
with Database("migrated_db") as db:
results = pg_migration.migrate_database(db)
print(f"Migrated {sum(results.values())} records")
MongoDB Migration
from pyhybriddb.migration import MongoDBMigration
from pyhybriddb import Database
# Connect to MongoDB
mongo_migration = MongoDBMigration({
'host': 'localhost',
'port': 27017,
'database': 'mydb'
})
# Migrate to PyHybridDB
with Database("migrated_db") as db:
results = mongo_migration.migrate_database(db)
print(f"Migrated {sum(results.values())} documents")
Encrypted Storage
from pyhybriddb.utils.encryption import EncryptionManager
# Setup encryption
encryption = EncryptionManager()
# Encrypt data
encrypted = encryption.encrypt_string("sensitive data")
# Decrypt data
decrypted = encryption.decrypt_string(encrypted)
# Encrypt files
encryption.encrypt_file("data.phdb", "data.phdb.encrypted")
encryption.decrypt_file("data.phdb.encrypted", "data.phdb")
๐ API Documentation
Base URL
http://localhost:8000/api
Interactive Docs
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Key Endpoints
Authentication
POST /api/auth/login- Login and get JWT tokenGET /api/auth/me- Get current user info
Databases
POST /api/databases- Create databaseGET /api/databases- List databasesGET /api/databases/{name}- Get database detailsDELETE /api/databases/{name}- Delete database
Backup & Restore โจ NEW!
POST /api/databases/{name}/backup- Create backupGET /api/databases/{name}/backups- List backupsPOST /api/databases/{name}/restore- Restore backup
Audit Logs โจ NEW!
GET /api/audit/logs- Get audit logs (admin only)GET /api/audit/statistics- Get audit statistics (admin only)
User Management โจ NEW!
POST /api/users- Create user (admin only)GET /api/users- List users (admin only)GET /api/users/{username}- Get user detailsPUT /api/users/{username}- Update user (admin only)DELETE /api/users/{username}- Delete user (admin only)
Data Visualization โจ NEW!
GET /api/databases/{db}/tables/{table}/visualize- Generate charts
Tables
POST /api/databases/{db}/tables- Create tableGET /api/databases/{db}/tables- List tablesPOST /api/databases/{db}/tables/{table}/records- Insert recordGET /api/databases/{db}/tables/{table}/records- Get records
Collections
POST /api/databases/{db}/collections- Create collectionPOST /api/databases/{db}/collections/{coll}/documents- Insert documentGET /api/databases/{db}/collections/{coll}/documents- Get documents
Query
POST /api/databases/{db}/query- Execute query (SQL or NoSQL)
๐ฅ๏ธ CLI Commands
Database Management
# Create database
python -m pyhybriddb.cli create my_database
# Database info
python -m pyhybriddb.cli info my_database
Server Management
# Start server
python -m pyhybriddb.cli serve
# Custom host and port
python -m pyhybriddb.cli serve --host 127.0.0.1 --port 8080
# Enable auto-reload
python -m pyhybriddb.cli serve --reload
Interactive Shell
# Start shell
python -m pyhybriddb.cli shell my_database
# In shell:
phdb> CREATE TABLE users (name string, age integer)
phdb> INSERT INTO users (name, age) VALUES ('Alice', 30)
phdb> SELECT * FROM users
phdb> db.posts.insertOne({"title": "Hello"})
phdb> exit
Configuration
# View configuration
python -m pyhybriddb.cli config
๐ Examples
Example 1: Basic CRUD
from pyhybriddb import Database
db = Database("example_db", path="./data")
db.create()
# Create table
users = db.create_table("users", {"name": "string", "age": "integer"})
# Insert
user_id = users.insert({"name": "Alice", "age": 30})
# Select
all_users = users.select()
# Update
users.update(where={"name": "Alice"}, updates={"age": 31})
# Delete
users.delete(where={"name": "Alice"})
db.close()
Example 2: NoSQL Collections
from pyhybriddb import Database
with Database("blog_db") as db:
posts = db.create_collection("posts")
# Insert
posts.insert_one({
"title": "My First Post",
"tags": ["intro"],
"views": 0
})
# Find
all_posts = posts.find()
intro_posts = posts.find({"tags": "intro"})
# Update
posts.update_one(
{"title": "My First Post"},
{"$inc": {"views": 1}}
)
# Aggregate
popular = posts.aggregate([
{"$sort": {"views": -1}},
{"$limit": 5}
])
See examples/basic_usage.py for more examples.
๐ Project Structure
D:\python_db\
โโโ pyhybriddb/ # Main package
โ โโโ config.py # Configuration
โ โโโ core/ # Database core
โ โ โโโ database.py
โ โ โโโ table.py
โ โ โโโ collection.py
โ โโโ storage/ # Storage engine
โ โ โโโ engine.py
โ โ โโโ file_manager.py
โ โ โโโ index.py
โ โโโ query/ # Query layer
โ โ โโโ parser.py
โ โ โโโ sql_parser.py
โ โ โโโ nosql_parser.py
โ โ โโโ joins.py # โจ JOIN operations
โ โโโ api/ # REST API
โ โ โโโ server.py
โ โ โโโ models.py
โ โ โโโ auth.py
โ โ โโโ users.py # โจ User management
โ โโโ utils/ # Utilities
โ โ โโโ backup.py # โจ Backup & restore
โ โ โโโ audit.py # โจ Audit logging
โ โ โโโ encryption.py # โจ Encryption
โ โ โโโ visualization.py # โจ Data visualization
โ โ โโโ serializer.py
โ โ โโโ logger.py
โ โโโ migration/ # โจ Migration tools
โ โ โโโ postgresql.py # PostgreSQL migration
โ โ โโโ mongodb.py # MongoDB migration
โ โโโ cli.py # CLI
โโโ admin/ # Web admin panel
โ โโโ index.html
โ โโโ app.js
โ โโโ auth.js
โโโ examples/ # Examples
โโโ tests/ # Tests
โโโ DEMO.py # Demo script
โโโ config.env # Config template
โโโ requirements.txt
โโโ setup.py
โโโ README.md # This file
๐งช Testing
Run Tests
# Run all tests
python -m unittest discover tests
# Run specific test
python -m unittest tests.test_database.TestDatabase
Example Test
import unittest
from pyhybriddb import Database
class TestDatabase(unittest.TestCase):
def test_create_database(self):
db = Database("test_db", path="./test_data")
db.create()
self.assertTrue(db.db_file.exists())
db.close()
๐ Security
Best Practices
-
Change Default Credentials
ADMIN_PASSWORD=YourSecurePassword123!
-
Use Strong SECRET_KEY
import secrets print(secrets.token_urlsafe(32))
-
Enable HTTPS in Production
-
Restrict CORS Origins
CORS_ORIGINS=https://yourdomain.com
-
Set Appropriate Log Level
LOG_LEVEL=WARNING
Security Features
- โ JWT token authentication
- โ Password hashing with bcrypt
- โ Token expiration (30 minutes)
- โ CORS protection
- โ Input validation
- โ Environment-based secrets
- โ Audit logging for compliance
- โ Encrypted storage option
๐ Implementation Status
โ 100% Feature Complete
All features from the original PRD have been successfully implemented!
| Feature | Status | File Location |
|---|---|---|
| Core Features | ||
| Hybrid Data Model | โ Complete | core/database.py, core/table.py, core/collection.py |
| Custom Storage Engine | โ Complete | storage/engine.py, storage/file_manager.py |
| B-Tree Indexing | โ Complete | storage/index.py |
| SQL Query Support | โ Complete | query/sql_parser.py |
| NoSQL Query Support | โ Complete | query/nosql_parser.py |
| ACID Transactions | โ Complete | core/database.py |
| REST API | โ Complete | api/server.py |
| Web Admin Panel | โ Complete | admin/index.html |
| JWT Authentication | โ Complete | api/auth.py |
| CLI Tools | โ Complete | cli.py |
| Environment Config | โ Complete | config.py |
| Advanced Features | ||
| Backup & Restore | โ Complete | utils/backup.py |
| Audit Logging | โ Complete | utils/audit.py |
| User Management | โ Complete | api/users.py |
| JOIN Operations | โ Complete | query/joins.py |
| Data Visualization | โ Complete | utils/visualization.py |
| PostgreSQL Migration | โ Complete | migration/postgresql.py |
| MongoDB Migration | โ Complete | migration/mongodb.py |
| Encrypted Storage | โ Complete | utils/encryption.py |
| Import/Export | โ Complete | admin/app.js |
Total: 20/20 Features (100%)
๐ Project Metrics
- Python Modules: 40+
- Lines of Code: ~10,000+
- API Endpoints: 25+
- Test Coverage: Core functionality
- Documentation: Comprehensive
๐ฏ Production Ready
โ
All core features implemented
โ
All advanced features implemented
โ
Security features complete
โ
Operational tools ready
โ
Migration tools available
โ
Comprehensive documentation
โ
Working examples provided
โ
Server tested and running
๐ Quick Start Guide
Installation
# Clone repository
git clone https://github.com/Adrient-tech/PyHybridDB.git
cd PyHybridDB
# Create virtual environment
python -m venv venv
.\venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install package
pip install -e .
Start Server
python -m pyhybriddb.cli serve
Server will start at: http://localhost:8000
Access Points
- API Docs: http://localhost:8000/docs
- Admin Panel: Open
admin/index.htmlin browser - Default Login: admin / admin123
Run Demo
python DEMO.py
๐ Support & Contributing
Support
- GitHub Issues: Report bugs and request features
- Documentation: See this README and inline docs
- Examples: Check
examples/directory
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Development Setup
# Install dev dependencies
pip install -r requirements.txt
# Run tests
python -m unittest discover tests
# Start with auto-reload
python -m pyhybriddb.cli serve --reload
๐ Learning Resources
- Quick Start: This README
- API Reference: http://localhost:8000/docs (when server running)
- Examples:
examples/basic_usage.py - Demo Script:
python DEMO.py - Original PRD:
project.md
๐ License
MIT License
Copyright (c) 2025 Adrient.com - Developed by Infant Nirmal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
๐ Support
- Issues: Report bugs on GitHub Issues
- Documentation: See this README and
project.md - Examples: Check
examples/directory - Demo: Run
python DEMO.py
๐ฏ Roadmap
Phase 1: Core Features โ COMPLETE
- โ Core storage engine
- โ Hybrid data model
- โ SQL & NoSQL query support
- โ REST API
- โ Admin panel
- โ JWT Authentication
- โ CLI Tools
Phase 2: Advanced Features โ COMPLETE
- โ Backup & Restore
- โ Audit Logging
- โ User Management
- โ JOIN Operations
- โ Data Visualization
- โ PostgreSQL Migration
- โ MongoDB Migration
- โ Encrypted Storage
- โ Import/Export
Phase 3: Future Enhancements (Optional)
- Multi-Factor Authentication (2FA)
- Full-Text Search
- Compound Indexes
- Advanced Query Optimization
- Replication & High Availability
- Sharding & Horizontal Scaling
- GraphQL API
- Real-time Subscriptions
- Cloud Storage Backends (S3, Azure, GCP)
- Plugin System & Extensions
๐ Acknowledgments
Inspired by:
- PostgreSQL - Relational model
- MongoDB - Document model
- SQLite - Embedded database
- phpMyAdmin - Admin interface
๐ Project Stats
- Lines of Code: ~10,000+
- Python Modules: 40+
- Total Files: 45+
- API Endpoints: 25+
- Features: 20/20 (100% Complete)
- Version: 1.0.0 (Production Ready)
- Python: 3.10+
- Platform: Cross-platform
- License: MIT
Built with โค๏ธ by Infant Nirmal at Adrient.com
GitHub: https://github.com/Adrient-tech/PyHybridDB.git
Last Updated: October 25, 2025
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 pyhybriddb-1.0.1.tar.gz.
File metadata
- Download URL: pyhybriddb-1.0.1.tar.gz
- Upload date:
- Size: 6.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef80010edd20eff580847b2f08dbe25f3a604bdeb4a219c55669b56ec73a8348
|
|
| MD5 |
b9a65af2d957a1d5e54ce1b42e636eae
|
|
| BLAKE2b-256 |
3ce2144dafc505371175469a0c389c3899fc54a3d8a03b9b2f8299230d0ccda3
|
File details
Details for the file pyhybriddb-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pyhybriddb-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afb40d7260db3048ff5dc4f58968076143d08d619af72cb167633ddc4ba1a02c
|
|
| MD5 |
a2b7565c3cb7a3a0ef374cd8aa9454f5
|
|
| BLAKE2b-256 |
fe0a1e17a60967671320445410a35c395fd431bd1bac3df4ed42d83f7fa281ed
|