Metadata-Version: 2.4
Name: hanifx-db
Version: 28.0.0
Summary: HanifX Database Engine — Custom binary database with built-in HanifX security encoding
Home-page: https://pypi.org/project/hanifx-db
Author: Hanif
Author-email: sajim4653@gmail.com
Project-URL: Source, https://pypi.org/project/hanifx-db
Project-URL: Tracker, https://pypi.org/project/hanifx-db
Keywords: database,db,hanifx,security,encoding,encryption,custom-database,binary-format,hxdb,termux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-python
Dynamic: summary

# HanifX DB 🗄️

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

[![Version](https://img.shields.io/badge/version-27.0.0-blue)](https://pypi.org/project/hanifx-db)
[![Python](https://img.shields.io/badge/python-3.6%2B-green)](https://pypi.org/project/hanifx-db)
[![License](https://img.shields.io/badge/license-MIT-orange)](LICENSE)
[![Platform](https://img.shields.io/badge/platform-Termux%20%7C%20Linux%20%7C%20Windows%20%7C%20Mac-lightgrey)](https://pypi.org/project/hanifx-db)

---

## ✨ 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

```bash
pip install hanifx-db
```

---

## 🚀 Quick Start

```python
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:

```python
# 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

```python
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

```python
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

```python
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

```python
# 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

```python
# Backup
db.backup("backup.hxbak")

# Restore
db.restore("backup.hxbak")
```

---

## 📊 Info & Logs

```python
# 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

```python
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

```bash
# 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](https://pypi.org/user/habib_bi)
- Email: sajim4653@gmail.com
- Package: [hanifx-db](https://pypi.org/project/hanifx-db)

---

## 📄 License

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