Document Inventory
Overview
This skill scans document collections (PDFs, Word docs, text files) and creates a structured inventory with metadata, automatic categorization, and collection statistics. Essential first step before building knowledge bases.
Quick Start
from pathlib import Path
import sqlite3
# Scan directory
documents = []
for filepath in Path("/path/to/docs").rglob("*.pdf"):
documents.append({
'filename': filepath.name,
'size': filepath.stat().st_size,
'path': str(filepath)
})
# Store in database
conn = sqlite3.connect("inventory.db")
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS docs (name TEXT, size INTEGER, path TEXT)")
for doc in documents:
cursor.execute("INSERT INTO docs VALUES (?, ?, ?)",
(doc['filename'], doc['size'], doc['path']))
conn.commit()
print(f"Inventoried {len(documents)} documents")
When to Use
- Auditing large document libraries before processing
- Understanding the scope of a document collection
- Categorizing documents by type, source, or content
- Preparing inventories for knowledge base creation
- Generating reports on document collections
- Identifying duplicates or organizing files
Features
- Recursive scanning - Process nested directories
- Metadata extraction - Size, dates, page counts
- Auto-categorization - Pattern-based classification
- Statistics generation - Collection summaries
- SQLite storage - Queryable inventory database
- Multiple formats - PDF, DOCX, TXT, and more
Implementation
Core Inventory Builder
#!/usr/bin/env python3
"""Document inventory builder."""
import sqlite3
import os
from pathlib import Path
from datetime import datetime
import logging
*See sub-skills for full details.*
### CLI Interface
```python
#!/usr/bin/env python3
"""Document Inventory CLI."""
import argparse
import json
def main():
parser = argparse.ArgumentParser(description='Document Inventory Tool')
subparsers = parser.add_subparsers(dest='command', help='Commands')
*See sub-skills for full details.*
### Report Generator
```python
def generate_report(db_path, output_path):
"""Generate HTML inventory report."""
inventory = DocumentInventory(db_path)
stats = inventory.get_statistics()
html = f"""
<!DOCTYPE html>
<html>
<head>
*See sub-skills for full details.*
## Custom Categorization
### Extend with Your Patterns
```python
# Add custom patterns for your domain
CUSTOM_PATTERNS = {
'SPEC': 'Specifications',
'DWG': 'Drawings',
'REV': 'Revisions',
'APPROVED': 'Approved',
'DRAFT': 'Draft',
'SUPERSEDED': 'Superseded',
}
*See sub-skills for full details.*
### Multi-Level Categories
```python
def categorize_hierarchical(filepath):
"""Create hierarchical categories."""
name = filepath.name.upper()
# Primary category
primary = 'General'
if 'API' in name:
primary = 'API Standards'
elif 'ISO' in name:
*See sub-skills for full details.*
## Example Usage
```bash
# Scan directory
python inventory.py scan /path/to/documents --db inventory.db
# View statistics
python inventory.py stats --db inventory.db
# Search
python inventory.py search "API" --category "Standards"
# Export to CSV
python inventory.py export inventory.csv --db inventory.db
Related Skills
knowledge-base-builder - Build searchable database after inventory
pdf/text-extractor - Extract text from inventoried PDFs
semantic-search-setup - Add AI search capabilities
Version History
- 1.1.0 (2026-01-02): Added Quick Start, Execution Checklist, Error Handling, Metrics sections; updated frontmatter with version, category, related_skills
- 1.0.0 (2024-10-15): Initial release with SQLite storage, auto-categorization, CLI interface
Sub-Skills
Sub-Skills
- Execution Checklist
- Error Handling
- Metrics
- Dependencies
1---2name: document-inventory3description: Scan and catalog document collections with metadata extraction, categorization, and statistics. Use for auditing document libraries, preparing for knowledge base creation, or understanding large file collections.4---56# Document Inventory78## Overview910This skill scans document collections (PDFs, Word docs, text files) and creates a structured inventory with metadata, automatic categorization, and collection statistics. Essential first step before building knowledge bases.1112## Quick Start1314```python15from pathlib import Path16import sqlite31718# Scan directory19documents = []20for filepath in Path("/path/to/docs").rglob("*.pdf"):21 documents.append({22 'filename': filepath.name,23 'size': filepath.stat().st_size,24 'path': str(filepath)25 })2627# Store in database28conn = sqlite3.connect("inventory.db")29cursor = conn.cursor()30cursor.execute("CREATE TABLE IF NOT EXISTS docs (name TEXT, size INTEGER, path TEXT)")31for doc in documents:32 cursor.execute("INSERT INTO docs VALUES (?, ?, ?)",33 (doc['filename'], doc['size'], doc['path']))34conn.commit()35print(f"Inventoried {len(documents)} documents")36```3738## When to Use3940- Auditing large document libraries before processing41- Understanding the scope of a document collection42- Categorizing documents by type, source, or content43- Preparing inventories for knowledge base creation44- Generating reports on document collections45- Identifying duplicates or organizing files4647## Features4849- **Recursive scanning** - Process nested directories50- **Metadata extraction** - Size, dates, page counts51- **Auto-categorization** - Pattern-based classification52- **Statistics generation** - Collection summaries53- **SQLite storage** - Queryable inventory database54- **Multiple formats** - PDF, DOCX, TXT, and more5556## Implementation5758### Core Inventory Builder5960```python61#!/usr/bin/env python362"""Document inventory builder."""6364import sqlite365import os66from pathlib import Path67from datetime import datetime68import logging697071*See sub-skills for full details.*72### CLI Interface7374```python75#!/usr/bin/env python376"""Document Inventory CLI."""7778import argparse79import json8081def main():82 parser = argparse.ArgumentParser(description='Document Inventory Tool')83 subparsers = parser.add_subparsers(dest='command', help='Commands')8485*See sub-skills for full details.*86### Report Generator8788```python89def generate_report(db_path, output_path):90 """Generate HTML inventory report."""91 inventory = DocumentInventory(db_path)92 stats = inventory.get_statistics()9394 html = f"""95 <!DOCTYPE html>96 <html>97 <head>9899*See sub-skills for full details.*100101## Custom Categorization102103### Extend with Your Patterns104105```python106# Add custom patterns for your domain107CUSTOM_PATTERNS = {108 'SPEC': 'Specifications',109 'DWG': 'Drawings',110 'REV': 'Revisions',111 'APPROVED': 'Approved',112 'DRAFT': 'Draft',113 'SUPERSEDED': 'Superseded',114}115116*See sub-skills for full details.*117### Multi-Level Categories118119```python120def categorize_hierarchical(filepath):121 """Create hierarchical categories."""122 name = filepath.name.upper()123124 # Primary category125 primary = 'General'126 if 'API' in name:127 primary = 'API Standards'128 elif 'ISO' in name:129130*See sub-skills for full details.*131132## Example Usage133134```bash135# Scan directory136python inventory.py scan /path/to/documents --db inventory.db137138# View statistics139python inventory.py stats --db inventory.db140141# Search142python inventory.py search "API" --category "Standards"143144# Export to CSV145python inventory.py export inventory.csv --db inventory.db146```147148## Related Skills149150- `knowledge-base-builder` - Build searchable database after inventory151- `pdf/text-extractor` - Extract text from inventoried PDFs152- `semantic-search-setup` - Add AI search capabilities153154## Version History155156- **1.1.0** (2026-01-02): Added Quick Start, Execution Checklist, Error Handling, Metrics sections; updated frontmatter with version, category, related_skills157- **1.0.0** (2024-10-15): Initial release with SQLite storage, auto-categorization, CLI interface158159## Sub-Skills160161- [Best Practices](best-practices/SKILL.md)162163## Sub-Skills164165- [Execution Checklist](execution-checklist/SKILL.md)166- [Error Handling](error-handling/SKILL.md)167- [Metrics](metrics/SKILL.md)168- [Dependencies](dependencies/SKILL.md)