HanifX DB 🗄️
HanifX Database Engine — A fully custom binary database built from scratch in pure Python with built-in HanifX security encoding.
✨ Features
- 🔐 Built-in HanifX Security — Irreversible encoding, no external dependency
- 🗂️ Multi-Table Support — Multiple tables in a single
.hxdbfile - ⚡ O(1) Index System — Custom hash table for fast lookups
- 🔄 Transactions + WAL — Commit, rollback, crash recovery
- 🗜️ Custom Compression — Own RLE + LZ algorithm
- 🔗 Relations — Foreign keys, ONE_TO_ONE, ONE_TO_MANY, MANY_TO_MANY
- 🔍 Query Builder — Fluent query API with 11 operators
- 💾 LRU Cache — Fast repeated reads
- 📝 Operation Logging — Every operation logged to
.hxlog - 📦 Pure Python — No external dependencies, works on Termux
📦 Installation
pip install hanifx-db
🚀 Quick Start
from hanifxdb import HanifXDB
# Open / Create database
db = HanifXDB("mydata.hxdb")
# Create table
db.create_table("users")
# Set plain data
db.set("users", "name", "Sazzad")
db.set("users", "age", 20)
db.set("users", "is_admin", True)
# Set secret data (irreversible HanifX encoding)
db.set_secret("users", "password", "mypass123")
# Get data
print(db.get("users", "name")) # Sazzad
print(db.get("users", "age")) # 20
# Verify secret
if db.verify("users", "password", "mypass123"):
print("Login success!")
# Close
db.close()
🔐 Security
HanifX DB uses the built-in HanifX 24.0.0 encoding algorithm:
# Store secret (irreversible)
db.set_secret("users", "token", "mytoken123")
# Verify (checksum-based)
db.verify("users", "token", "mytoken123") # True
db.verify("users", "token", "wrongtoken") # HanifXVerifyError
# Encode file
db.set_file("users", "photo", "profile.jpg")
# Generate secure token
token = db.generate_token(32)
uid = db.generate_id()
🗂️ Multi-Table
db = HanifXDB("shop.hxdb")
db.create_table("users")
db.create_table("orders")
db.create_table("products")
db.set("users", "user_1", {"name": "Sazzad", "age": 20})
db.set("products", "prod_1", {"name": "Phone", "price": 500})
db.set("orders", "ord_1", {"user": "user_1", "product": "prod_1"})
print(db.list_tables()) # ['users', 'orders', 'products']
🔍 Query Builder
from hanifxdb import OP_GTE, OP_LIKE
# Fluent query
results = (
db.query("users")
.where("age", OP_GTE, 18)
.where("name", OP_LIKE, "saz")
.order_by("age")
.limit(10)
.execute()
)
# Shortcuts
db.find_all("users")
db.find_one("users", "name", "Sazzad")
db.find_like("users", "name", "saz")
db.count("users")
🔄 Transactions
db.begin()
try:
db.set("users", "name", "Sazzad")
db.set("users", "age", 20)
db.set_secret("users", "password", "pass123")
db.commit()
except Exception:
db.rollback()
🔗 Relations
# Add relation
db.add_relation(
name = "user_orders",
from_table = "orders",
from_key = "user_id",
to_table = "users",
to_key = "id"
)
# Get related records
related = db.get_related("user_orders", "user_1")
# Validate foreign key
db.validate_fk("user_orders", "user_1")
💾 Backup & Restore
# Backup
db.backup("backup.hxbak")
# Restore
db.restore("backup.hxbak")
📊 Info & Logs
# Database info
print(db.info())
# Cache stats
print(db.cache_stats())
# Read logs
logs = db.read_logs()
for log in logs:
print(log)
🖥️ Context Manager
with HanifXDB("mydata.hxdb") as db:
db.create_table("users")
db.set("users", "name", "Sazzad")
# Auto close on exit
📁 File Format
HanifX DB uses a custom binary .hxdb format:
HANIFXDB ← Magic header (8 bytes)
Version ← DB version (4 bytes)
Timestamps ← Created / Modified
Table sections ← HX_TBL__ + records
Records ← HX_REC__ + key + value + checksum
HX_END__ ← EOF signature
📋 Supported Data Types
| Type | Python | Example |
|---|---|---|
| text | str | "Sazzad" |
| number | int / float | 20, 3.14 |
| bool | bool | True, False |
| secret | str (encoded) | "password123" → encoded |
| file | str (path) | "photo.jpg" → encoded |
| list | list | [1, 2, 3] |
| dict | dict | {"name": "Sazzad"} |
⚡ Query Operators
| Operator | Meaning |
|---|---|
OP_EQ |
Equal |
OP_NEQ |
Not equal |
OP_GT |
Greater than |
OP_GTE |
Greater than or equal |
OP_LT |
Less than |
OP_LTE |
Less than or equal |
OP_IN |
Value in list |
OP_NOT_IN |
Value not in list |
OP_LIKE |
String contains |
OP_STARTS |
String starts with |
OP_ENDS |
String ends with |
📱 Termux Support
# Install on Termux (Android)
pip install hanifx-db
# Use immediately - no extra setup needed
python3 -c "from hanifxdb import HanifXDB; print('HanifX DB ready!')"
👨💻 Author
Hanif (HanifX)
- PyPI: habib_bi
- Email: sajim4653@gmail.com
- Package: hanifx-db
📄 License
MIT License — Free to use, modify, and distribute.
Release files for hanifx-db 28.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hanifx_db-28.0.0.tar.gz | 7.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hanifx_db-28.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / hanifx_db-28.0.0.tar.gz
| Download URL | hanifx_db-28.0.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6a8a0de393275f0bf0e03b7338964f781e1b7f8971b0bc9eabfe2cc4f638471
|
|
BLAKE2b-256 checksum How to use checksums |
892a22ca29576438aa83c7b4476648ff051f9ab597e150bebe305973dbd57a77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / hanifx_db-28.0.0-py3-none-any.whl
| Download URL | hanifx_db-28.0.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a78305aadf6ff800d9242fc6c990dcc9ab7a4e1c2153b50adcef7226d567d36
|
|
BLAKE2b-256 checksum How to use checksums |
c3467511def6f310b67d18de8a8bcf2a8cf34e439b75f512ad45bdbe2e5b6ddb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|