Skip to main content

HanifX Database Engine — Custom binary database with built-in HanifX security encoding

Project description

HanifX DB 🗄️

HanifX Database Engine — A fully custom binary database built from scratch in pure Python with built-in HanifX security encoding.

Version Python License Platform


✨ Features

  • 🔐 Built-in HanifX Security — Irreversible encoding, no external dependency
  • 🗂️ Multi-Table Support — Multiple tables in a single .hxdb file
  • 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)


📄 License

MIT License — Free to use, modify, and distribute.

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

hanifx_db-28.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

hanifx_db-28.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file hanifx_db-28.0.0.tar.gz.

File metadata

  • Download URL: hanifx_db-28.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for hanifx_db-28.0.0.tar.gz
Algorithm Hash digest
SHA256 c6a8a0de393275f0bf0e03b7338964f781e1b7f8971b0bc9eabfe2cc4f638471
MD5 4c38e1ee6f90ea6b5a11eaa5ac676787
BLAKE2b-256 892a22ca29576438aa83c7b4476648ff051f9ab597e150bebe305973dbd57a77

See more details on using hashes here.

File details

Details for the file hanifx_db-28.0.0-py3-none-any.whl.

File metadata

  • Download URL: hanifx_db-28.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for hanifx_db-28.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a78305aadf6ff800d9242fc6c990dcc9ab7a4e1c2153b50adcef7226d567d36
MD5 0a1d7f3e7c7c2a928c3db23d9d1189ae
BLAKE2b-256 c3467511def6f310b67d18de8a8bcf2a8cf34e439b75f512ad45bdbe2e5b6ddb

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