A production-minded FastAPI backend for uploading, validating, and extracting structured content from multiple document formats.
π€ Document Upload β’ π‘οΈ File Validation β’ π Text Extraction β’ π Structured Metadata β’ π§ͺ 142 Passing Tests
AI File Analyzer is a backend application built with Python and FastAPI that accepts document uploads, validates them, and extracts their readable content into a structured format.
The application supports six document formats: TXT, PDF, DOCX, CSV, XLS, and XLSX.
Each uploaded document passes through a dedicated validation service before being processed by the document extraction service. The extracted result includes normalized content, document metadata, and individual content sections.
The project focuses on building a reliable document-processing foundation with structured responses, sensible resource limits, and predictable error handling.
- π€ Document Upload: Upload documents through a REST API.
- π‘οΈ File Validation: Validate filenames, extensions, empty files, and upload sizes.
- π Multi-format Extraction: Extract content from TXT, PDF, DOCX, CSV, XLS, and XLSX files.
- π Structured Output: Preserve useful information such as PDF page numbers, DOCX paragraph and table details, CSV rows, and Excel sheet metadata.
- π Resource Limits: Apply configurable limits to document extraction and processing.
β οΈ Error Handling: Handle invalid documents, malformed files, and extraction failures through predictable API responses.- π§ͺ Automated Testing: Unit tests and upload endpoint integration tests.
| Technology | Purpose |
|---|---|
| Python | Backend programming language |
| FastAPI | REST API framework |
| Pydantic | Data validation and response schemas |
| Pydantic Settings | Environment-based configuration |
| PyMuPDF | PDF text extraction |
| python-docx | DOCX document extraction |
| Pandas | Tabular data processing |
| openpyxl | XLSX workbook handling |
| xlrd | XLS workbook handling |
| Pytest | Automated testing |
backend/
β
βββ app/
β βββ api/
β β βββ routes/
β β βββ document.py
β β
β βββ core/
β β βββ config.py
β β βββ exceptions.py
β β
β βββ exceptions/
β β βββ handlers.py
β β
β βββ schemas/
β β βββ document.py
β β βββ extracted_document.py
β β
β βββ services/
β β βββ document_validation_service.py
β β βββ document_extraction_service.py
β β
β βββ main.py
β
βββ tests/
β βββ unit/
β βββ api/
β
βββ .env.example
βββ .gitignore
βββ requirements.txt
βββ README.md
Client
β
βΌ
Upload Endpoint
β
βΌ
Document Validation
Service
β
βΌ
Read File Bytes
β
βΌ
Document Extraction
Service
β
βΌ
Extracted Document
β
βΌ
Structured JSON
Response
Follow these steps to clone, configure, run, and test the application locally.
git clone <repository-url>Navigate into the backend directory:
cd <repository-folder>/backendpython -m venv .venvActivate it:
Linux / macOS:
source .venv/bin/activateWindows:
.venv\Scripts\activatepython -m pip install --upgrade pippip install -r requirements.txtCreate your local environment file:
cp .env.example .envOpen .env and configure the application settings as required.
From the backend directory, run:
uvicorn app.main:app --reloadThe application will start locally at:
http://127.0.0.1:8000
Navigate to:
http://127.0.0.1:8000/docs
Swagger UI provides an interactive interface for testing the available API endpoints.
- Open the
/documents/uploadendpoint. - Click Try it out.
- Select a supported document.
- Click Execute.
- Inspect the response containing the extracted content, sections, and metadata.
You can also check the application health using:
http://127.0.0.1:8000/health
From the backend directory:
pytest -qThe current test suite contains 142 passing tests.
AI File Analyzer is built around a simple principle: reliable AI applications begin with reliable data processing.
Clean inputs. Structured extraction. Predictable outputs.