Skip to main content

An advanced universal document loader - load TXT, CSV, JSON, XML, YAML, INI, HTML, PDF, DOCX, PPTX, XLSX with smart auto-detection

Project description

smartdocloader

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

Installation

pip install smartdocloader

For YAML support:

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

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)

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

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

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

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

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

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

from smartdocloader import load_yaml

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

Loading INI/Config Files

from smartdocloader import load_ini

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

Loading HTML (Text Extraction)

from smartdocloader import load_html

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

Searching Within Loaded Content

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

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

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

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

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

from smartdocloader import supported_formats

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

Error Handling

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

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

smartdocloader-1.0.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

smartdocloader-1.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file smartdocloader-1.0.0.tar.gz.

File metadata

  • Download URL: smartdocloader-1.0.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for smartdocloader-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dd39d465daf4190003e377e03293075cb0eb8458e68475a659491b1e8ab75169
MD5 170c7a41cb0e1894ecc4c1275fbc6a5d
BLAKE2b-256 fa31122eb8ccf1512271fc23a8b2d0cd8c63c8d46e9b0bfccc7b9cbb33947528

See more details on using hashes here.

File details

Details for the file smartdocloader-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: smartdocloader-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for smartdocloader-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fc756634cfc2fb0c88cebc8056a443742ec57dba1ce417502692faaee9ecba5
MD5 1989e1489a21d6e8b3ca6534a0213d2a
BLAKE2b-256 75943a9338aac976dc668297ffa409991fb015c8517488e6c6b1a7fdf739b0a9

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