Metadata-Version: 2.4
Name: smartdocloader
Version: 1.0.0
Summary: An advanced universal document loader - load TXT, CSV, JSON, XML, YAML, INI, HTML, PDF, DOCX, PPTX, XLSX with smart auto-detection
Author: Your Name
Author-email: your.email@example.com
License: MIT
Project-URL: Source, https://github.com/yourusername/smartdocloader
Keywords: document,loader,pdf,docx,xlsx,csv,json,yaml,parser,reader
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
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: Topic :: Software Development :: Libraries
Classifier: Topic :: Text Processing
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: PyPDF2
Requires-Dist: python-docx
Requires-Dist: python-pptx
Requires-Dist: openpyxl
Provides-Extra: yaml
Requires-Dist: pyyaml; extra == "yaml"
Provides-Extra: all
Requires-Dist: pyyaml; extra == "all"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# smartdocloader

An advanced universal document loader for Python. Smart auto-detection, batch loading, content search, and support for 11+ file formats.

## Installation

```bash
pip install smartdocloader
```

For YAML support:
```bash
pip install smartdocloader[yaml]
```

## Features

- **Auto-detection**: Automatically detects file type and uses the right loader
- **Batch loading**: Load multiple files in one call
- **11 formats supported**: TXT, CSV, JSON, XML, YAML, INI, HTML, PDF, DOCX, PPTX, XLSX
- **Content search**: Search within loaded data
- **Export**: Convert loaded data to JSON
- **File comparison**: Compare content of two files
- **Advanced options**: Page ranges for PDFs, sheet selection for Excel, table extraction from Word

---

## Quick Start

```python
from smartdocloader import auto_load

# Just pass any file - it auto-detects the format
data = auto_load("report.pdf")
data = auto_load("data.csv")
data = auto_load("config.yaml")
```

---

## All Supported Formats

| Format | Extensions | Module |
|--------|-----------|--------|
| Plain Text | `.txt` | text_loader |
| CSV | `.csv` | text_loader |
| JSON | `.json` | text_loader |
| XML | `.xml` | text_loader |
| YAML | `.yaml`, `.yml` | text_loader |
| INI/Config | `.ini`, `.cfg` | text_loader |
| HTML | `.html`, `.htm` | text_loader |
| PDF | `.pdf` | doc_loader |
| Word | `.docx` | doc_loader |
| PowerPoint | `.pptx` | doc_loader |
| Excel | `.xlsx` | doc_loader |

---

## Modules & Functions

### Module 1: `text_loader`

| Function | Description |
|----------|-------------|
| `load_txt(filepath, encoding)` | Load plain text file |
| `load_csv(filepath, delimiter, encoding)` | Load CSV as list of dicts |
| `load_json(filepath, encoding)` | Load and parse JSON |
| `load_xml(filepath)` | Load XML as nested dict |
| `load_yaml(filepath, encoding)` | Load YAML data |
| `load_ini(filepath, encoding)` | Load INI as nested dict |
| `load_html(filepath, encoding)` | Extract text from HTML |

### Module 2: `doc_loader`

| Function | Description |
|----------|-------------|
| `load_pdf(filepath, page_range)` | Extract text from PDF (optional page range) |
| `load_pdf_pages(filepath)` | Get text per page as a list |
| `load_pdf_metadata(filepath)` | Get PDF metadata (author, title, etc.) |
| `load_docx(filepath, include_tables)` | Load Word document paragraphs |
| `load_docx_with_styles(filepath)` | Load with style/formatting info |
| `load_pptx(filepath, include_notes)` | Load PowerPoint slides |
| `load_xlsx(filepath, sheet_name)` | Load Excel data from specific sheet |
| `load_xlsx_sheets(filepath)` | List all sheet names |

### Module 3: `smart_loader`

| Function | Description |
|----------|-------------|
| `auto_load(filepath)` | Auto-detect format and load |
| `batch_load(filepaths)` | Load multiple files at once |
| `get_file_info(filepath)` | Get file metadata (size, type, etc.) |
| `supported_formats()` | List all supported extensions |

### Module 4: `utils`

| Function | Description |
|----------|-------------|
| `search_content(data, keyword)` | Search within loaded content |
| `convert_to_text(data)` | Convert any loaded data to plain text |
| `word_count(data)` | Count words in loaded content |
| `export_to_json(data, output_path)` | Export loaded data to JSON file |
| `compare_files(filepath1, filepath2)` | Compare two files |

---

## Usage Examples

### Auto-Loading (Smart Detection)

```python
from smartdocloader import auto_load

# Just pass any file path - format is auto-detected
pdf_content = auto_load("report.pdf")
csv_data = auto_load("students.csv")
config = auto_load("settings.yaml")

print(pdf_content[:100])
```

### Batch Loading Multiple Files

```python
from smartdocloader import batch_load

files = ["data.csv", "report.pdf", "config.json", "notes.txt"]
results = batch_load(files)

for filepath, content in results.items():
    if "error" in content if isinstance(content, dict) else False:
        print(f"Failed: {filepath} - {content['error']}")
    else:
        print(f"Loaded: {filepath}")
```

### Loading PDFs with Options

```python
from smartdocloader import load_pdf, load_pdf_pages, load_pdf_metadata

# Load entire PDF
full_text = load_pdf("book.pdf")

# Load only pages 0-4 (first 5 pages)
intro = load_pdf("book.pdf", page_range=(0, 5))

# Get text per page
pages = load_pdf_pages("book.pdf")
print(f"Page 1: {pages[0][:100]}")
print(f"Total pages: {len(pages)}")

# Get metadata
meta = load_pdf_metadata("book.pdf")
print(f"Author: {meta['author']}")
print(f"Title: {meta['title']}")
print(f"Pages: {meta['page_count']}")
```

### Loading Word Documents

```python
from smartdocloader import load_docx, load_docx_with_styles

# Basic loading
paragraphs = load_docx("report.docx")
for p in paragraphs:
    print(p)

# With tables included
content = load_docx("report.docx", include_tables=True)
for item in content:
    print(item)

# With style information
styled = load_docx_with_styles("report.docx")
for para in styled:
    if para["bold"]:
        print(f"[BOLD] {para['text']}")
    else:
        print(f"       {para['text']}")
```

### Loading Excel with Sheet Selection

```python
from smartdocloader import load_xlsx, load_xlsx_sheets

# See available sheets
sheets = load_xlsx_sheets("financials.xlsx")
print(f"Sheets: {sheets}")

# Load specific sheet
q1_data = load_xlsx("financials.xlsx", sheet_name="Q1")
for row in q1_data:
    print(row)
```

### Loading PowerPoint with Notes

```python
from smartdocloader import load_pptx

slides = load_pptx("lecture.pptx", include_notes=True)
for slide in slides:
    print(f"--- Slide {slide['slide_number']} ---")
    for text in slide["text"]:
        print(f"  {text}")
    if "notes" in slide and slide["notes"]:
        print(f"  [Notes: {slide['notes']}]")
```

### Loading YAML Configuration

```python
from smartdocloader import load_yaml

config = load_yaml("docker-compose.yml")
print(config["services"])
```

### Loading INI/Config Files

```python
from smartdocloader import load_ini

settings = load_ini("app.ini")
print(settings["database"]["host"])
print(settings["database"]["port"])
```

### Loading HTML (Text Extraction)

```python
from smartdocloader import load_html

text = load_html("page.html")
print(text)  # Clean text without HTML tags
```

### Searching Within Loaded Content

```python
from smartdocloader import auto_load, search_content

# Load any file
data = auto_load("students.csv")

# Search for a keyword
matches = search_content(data, "Ahmed")
print(f"Found {len(matches)} matches:")
for match in matches:
    print(f"  {match}")
```

### Converting to Plain Text

```python
from smartdocloader import auto_load, convert_to_text

# Load structured data
data = auto_load("grades.xlsx")

# Convert to flat text
text = convert_to_text(data)
print(text)
```

### Exporting to JSON

```python
from smartdocloader import auto_load, export_to_json

# Load a Word document
data = auto_load("report.docx")

# Export as JSON for further processing
export_to_json(data, "report_output.json")
```

### Comparing Two Files

```python
from smartdocloader import compare_files

result = compare_files("version1.txt", "version2.txt")
print(f"Identical: {result['identical']}")
print(f"File 1: {result['file1_lines']} lines, {result['file1_words']} words")
print(f"File 2: {result['file2_lines']} lines, {result['file2_words']} words")
```

### Getting File Info

```python
from smartdocloader import get_file_info

info = get_file_info("report.pdf")
print(f"Name: {info['name']}")
print(f"Size: {info['size_readable']}")
print(f"Supported: {info['is_supported']}")
```

### Listing Supported Formats

```python
from smartdocloader import supported_formats

formats = supported_formats()
print(f"Supported: {', '.join(formats)}")
```

---

## Error Handling

```python
from smartdocloader import auto_load

try:
    data = auto_load("unknown.xyz")
except ValueError as e:
    print(f"Format error: {e}")
except FileNotFoundError as e:
    print(f"File missing: {e}")
except Exception as e:
    print(f"Error: {e}")
```

---

## Requirements

- Python >= 3.7
- PyPDF2
- python-docx
- python-pptx
- openpyxl
- pyyaml (optional, for YAML support)

---

## License

MIT
