dtl-parser 1.4.1
DTL (Domain Transport Language) Parser - Smart Tool with enum validation, autofix, and beautiful CLI
License: MIT
Requires Python: >=3.8
Keywords: dtl, parser, data-format, domain-transport-language, enum, validation, autofix, smart-tool, cli, json, csv, healthcare, finance, web3, alifzetta, dubai, emirates

# 🧬 DTL Parser

**Domain Transport Language SDK for Python - Smart Tool Edition**

[![PyPI version](https://badge.fury.io/py/dtl-parser.svg)](https://badge.fury.io/py/dtl-parser)
[![Python](https://img.shields.io/pypi/pyversions/dtl-parser.svg)](https://pypi.org/project/dtl-parser/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

```
╔══════════════════════════════════════════════════════════════════════════════╗
║                                                                              ║
║     ██████╗ ████████╗██╗         ██████╗  █████╗ ██████╗ ███████╗███████╗   ║
║     ██╔══██╗╚══██╔══╝██║         ██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔════╝   ║
║     ██║  ██║   ██║   ██║         ██████╔╝███████║██████╔╝███████╗█████╗     ║
║     ██║  ██║   ██║   ██║         ██╔═══╝ ██╔══██║██╔══██╗╚════██║██╔══╝     ║
║     ██████╔╝   ██║   ███████╗    ██║     ██║  ██║██║  ██║███████║███████╗   ║
║     ╚═════╝    ╚═╝   ╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝   ║
║                                                                              ║
║              ⭐ Domain Transport Language - Smart Parser ⭐                  ║
║                                                                              ║
║     🇦🇪  Product of Dubai, Made in Emirates                                  ║
║         Born in Dubai, Built for the World                                   ║
║                                                                              ║
╚══════════════════════════════════════════════════════════════════════════════╝
```

---

## ✨ Features

- **🧠 Smart Tool** - Intelligent DTL processing with auto-detection
- **📊 Full DTL Parsing** - Parse DTL files and strings with complete type support
- **✅ Enum Validation** - Exact-match validation with up to 10 values per field
- **🔧 Autofix / Magic Corrections** - Automatically fix common errors
- **🔍 Fuzzy Matching** - Smart typo suggestions using Levenshtein distance
- **📤 Multi-Format Export** - Convert to JSON or CSV
- **🏭 Programmatic Creation** - Create tables and documents in code
- **🎨 Beautiful CLI** - Colorful command-line interface
- **📝 Type-Safe** - Full type hints for IDE support

---

## 📦 Installation

```bash
pip install dtl-parser
```

---

## 🚀 Quick Start

### CLI Usage (Smart Tool)

```bash
# Show beautiful banner
dtl --banner

# Parse and analyze a file
dtl analyze data.dtl

# Validate with suggestions
dtl validate data.dtl

# Auto-fix errors
dtl fix data.dtl --output fixed.dtl

# Convert to JSON
dtl convert data.dtl --format json

# Pretty print
dtl parse data.dtl --pretty
```

### Python API

```python
from dtl_parser import DTLParser, SmartTool, print_banner

# Show the magical banner ✨
print_banner()

# Parse a DTL file
parser = DTLParser()
doc = parser.parse_file("data.dtl")

# Use the Smart Tool
tool = SmartTool()

# Analyze the file
analysis = tool.analyze("data.dtl")
print(f"Health Score: {analysis['health_score']}/100")

# Pretty print with colors
tool.pretty_print(doc)

# Health check
health = tool.health_check(doc)
print(f"Status: {health['status']}")
```

---

## 🧠 Smart Tool Features

### Auto Schema Inference

```python
from dtl_parser import SmartTool

tool = SmartTool()

# Infer schema from raw data
data = [
    {"id": "U001", "name": "Alice", "status": "active", "score": 95},
    {"id": "U002", "name": "Bob", "status": "inactive", "score": 87},
    {"id": "U003", "name": "Charlie", "status": "active", "score": 92},
]

# SmartTool detects types and creates enum for 'status'
table = tool.infer_schema(data, "USERS")
print(table.to_dtl())

# Output:
# USERS|id:s,name:s,status:e(active,inactive),score:i|3|S0|W0|C0
# U001|Alice|active|95
# ...
```

### Intelligent Query

```python
# Query with filters
active_users = tool.query(users_table, status="active")
admins = tool.query(users_table, role="admin", status="active")
```

### Health Check

```python
health = tool.health_check(doc)
# Returns:
# {
#   "status": "healthy",  # healthy | warning | critical
#   "score": 95,
#   "checks": [...],
#   "recommendations": [...]
# }
```

---

## ✅ Validation

```python
from dtl_parser import DTLParser

parser = DTLParser()
doc = parser.parse_file("data.dtl")

# Validate and get errors with suggestions
errors = doc.validate()

for error in errors:
    print(f"[{error.severity.value}] Line {error.line}: {error.message}")
    if error.suggestion:
        print(f"  💡 Suggestion: {error.suggestion}")
```

---

## 🔧 Autofix

```python
from dtl_parser import DTLParser

dtl_with_errors = """
@dtlv1.0^dtWEB^pDemo^c0^s0^w0^hash
@sec^none^0x0^none^0

users|id:s,status:e(active,inactive,pending)|2|S0|W0|C0
U001|actve
U002|pendng
U003|inactive
"""

parser = DTLParser()
doc = parser.parse(dtl_with_errors)

# Apply autofix ✨
fixed_doc, changes = doc.autofix()

for change in changes:
    print(f"✨ {change}")

# Output:
# ✨ Fixed table name case: users → USERS
# ✨ Fixed row count in USERS: 2 → 3
# ✨ Fixed USERS[0].status: 'actve' → 'active'
# ✨ Fixed USERS[1].status: 'pendng' → 'pending'
```

---

## 🏭 Create Tables Programmatically

```python
from dtl_parser import create_table, create_document

# Create a table with enum fields
orders = create_table("ORDERS", {
    "id": "s",
    "customer": "s",
    "status": "e(pending,confirmed,shipped,delivered)",
    "priority": "e(low,medium,high,urgent)",
    "total": "f",
    "created": "D"
})

# Add rows
orders.add_row({
    "id": "ORD-001",
    "customer": "Alice",
    "status": "pending",
    "priority": "high",
    "total": 99.99,
    "created": "2025-01-15"
})

# Create document and export
doc = create_document(domain="dtWEB")
doc.add_table(orders)
print(doc.to_dtl())
```

---

## 📊 DTL Data Types

| Type | Code | Description | Example |
|------|------|-------------|---------|
| String | `s` | Text value | `Hello World` |
| Integer | `i` | Whole number | `42` |
| Float | `f` | Decimal number | `3.14` |
| Boolean | `b` | 0 or 1 | `1` |
| Date | `D` | YYYY-MM-DD | `2025-01-15` |
| Timestamp | `T` | ISO 8601 | `2025-01-15T10:30:00Z` |
| UUID | `u` | Unique ID | `550e8400-e29b-...` |
| JSON | `j` | Embedded JSON | `{"key":"value"}` |
| Array | `a(x)` | List of type x | `a,b,c` |
| **Enum** | `e(...)` | Exact match | `e(low,medium,high)` |

---

## 🏥 Domain Examples

### Healthcare (dtHC)

```python
patients = create_table("PATIENTS", {
    "mrn": "s",
    "name": "s",
    "gender": "e(M,F,O)",
    "blood_type": "e(A+,A-,B+,B-,AB+,AB-,O+,O-)",
    "status": "e(active,discharged,deceased)"
}, security="S2")  # HIPAA compliant
```

### Finance (dtFN)

```python
transactions = create_table("TRANSACTIONS", {
    "id": "u",
    "type": "e(deposit,withdrawal,transfer)",
    "currency": "e(USD,EUR,GBP,AED)",
    "amount": "f",
    "status": "e(pending,completed,failed)"
}, web3="W1")  # With blockchain signature
```

---

## 🎨 Beautiful Output

```python
from dtl_parser import print_banner, Colors

# Print the banner
print_banner()       # Full banner
print_banner(mini=True)  # Compact banner

# Use colors in your output
print(f"{Colors.TEAL}DTL is awesome!{Colors.ENDC}")
print(f"{Colors.GREEN}✅ Success{Colors.ENDC}")
print(f"{Colors.RED}❌ Error{Colors.ENDC}")
```

---

## 📜 License

MIT License - see [LICENSE](LICENSE) file.

---

## 👤 Author

**Padam Sundar Kafle**  
Lead Architect, DTL & AlifZetta  
📧 padam@axz.si

---

## 🔗 Links

- **Website:** [dtlaz.org](https://dtlaz.org)
- **Documentation:** [dtlaz.org/docs](https://dtlaz.org/docs.html)
- **GitHub:** [github.com/AlifZetta/dtl-parser-python](https://github.com/AlifZetta/dtl-parser-python)

---

🇦🇪 **Product of Dubai, Made in Emirates**

*Born in Dubai, Built for the World*

✨ **Version 1.4.1 - Smart Tool Edition** ✨