Skip to main content

PDF Mapper Module

The core PDF field extraction, mapping, embedding, and filling engine.

🚀 Quick Start

1. Configure the Module

IMPORTANT: You must configure before running!

# Copy configuration templates
cp .env.example .env
cp config.ini.example config.ini

# Edit .env - Add your API keys
nano .env

# Edit config.ini - Set your storage paths
nano config.ini

See SETUP_GUIDE.md for detailed configuration instructions.

2. Install Dependencies

# Core dependencies
pip install -r requirements.txt

# For API server
pip install -r requirements-api.txt

3. Run API Server

Set API_KEY first — the server refuses to serve requests without it (see Environment Variables below).

export API_KEY=change-me-to-a-long-random-secret
python api_server.py

Server will be available at: http://localhost:8000

Interactive docs at: http://localhost:8000/docs


📁 File Structure

modules/mapper/
├── .env.example            ← Copy to .env (add your API keys)
├── config.ini.example      ← Copy to config.ini (configure paths)
├── config.ini              ← Active configuration (DO NOT COMMIT)
├── .env                    ← Active environment (DO NOT COMMIT)
├── SETUP_GUIDE.md          ← Detailed setup instructions
├── API_SERVER.md           ← API server documentation
├── api_server.py           ← FastAPI server (run this!)
├── requirements.txt        ← Python dependencies
├── requirements-api.txt    ← API server dependencies
├── setup.py                ← Package setup
└── src/                    ← Core source code
    ├── orchestrator.py     ← Main orchestration logic
    ├── extractors/         ← PDF field extraction
    ├── mappers/            ← Field mapping (LLM)
    ├── embedders/          ← Metadata embedding
    ├── fillers/            ← PDF filling
    ├── chunkers/           ← Document chunking
    ├── groupers/           ← Field grouping
    ├── headers/            ← Header detection
    ├── validators/         ← Field validation
    └── core/               ← Configuration & logging

🎯 What This Module Does

  1. Extract - Extracts form fields from PDF files
  2. Map - Maps extracted fields to your data schema using LLM
  3. Embed - Embeds mapping metadata into PDF for reuse
  4. Fill - Fills embedded PDFs with actual data

Operations

Operation Input Output Use Case
extract PDF file Field list JSON Discover what fields exist
map Extracted fields Mapping JSON Create field-to-schema mapping
embed PDF + mapping Embedded PDF Prepare PDF for filling
fill Embedded PDF + data Filled PDF Generate completed forms
make-embed PDF file Embedded PDF One-step: extract+map+embed
run-all PDF + data Filled PDF Complete pipeline

🔧 Configuration Overview

Required Configuration

In .env:

# Choose one
CLOUD_PROVIDER=local          # For local development
# CLOUD_PROVIDER=aws          # For AWS deployment
# CLOUD_PROVIDER=azure        # For Azure deployment

# Add your LLM API key
OPENAI_API_KEY=sk-your-key-here

In config.ini:

[general]
source_type = local

[mapping]
llm_model = gpt-4o
use_second_mapper = false

[local]
cache_registry_path = /path/to/cache/hash_registry.json
output_base_path = /path/to/output

See SETUP_GUIDE.md for complete details.


🌐 Running as API Server

# Start server
python api_server.py

# In another terminal, test it
curl http://localhost:8000/health

Authentication is required. Set API_KEY to a strong secret before starting the server — every endpoint except /, /health, /docs, and /redoc requires it as the X-API-Key header, or the server responds with a config error. (For local-only experimentation you can instead set MAPPER_ALLOW_INSECURE_NO_AUTH=true, but never do this in a deployment reachable by anyone else.) Cross-origin access defaults to open (*) for convenience during local development — set MAPPER_CORS_ALLOWED_ORIGINS (comma-separated) to lock this down before deploying.

Available endpoints:

  • GET / - API info
  • GET /health - Health check
  • POST /mapper/extract - Extract fields
  • POST /mapper/map - Map fields
  • POST /mapper/embed - Embed metadata
  • POST /mapper/fill - Fill PDF
  • POST /mapper/make-embed - Extract+Map+Embed
  • POST /mapper/fill-pdf - Fill embedded PDF
  • POST /mapper/check-embed-file - Check if PDF has embeddings
  • POST /mapper/run-all - Complete pipeline

See API_SERVER.md for API documentation.


📦 Using as Python Module

from src.orchestrator import run_extraction, run_mapping, run_embedding, run_filling

# Extract fields
extracted = run_extraction(pdf_path, user_id, pdf_doc_id)

# Map fields
mapped = run_mapping(user_id, pdf_doc_id)

# Embed metadata
embedded = run_embedding(pdf_path, user_id, pdf_doc_id)

# Fill PDF
filled = run_filling(embedded_pdf_path, user_id, pdf_doc_id, input_data)

🧪 Testing

# Run all tests
pytest

# Run specific test
pytest tests/test_extract.py

# With coverage
pytest --cov=src

🐳 Deployment Options

Local Development

python api_server.py

Docker

docker build -t pdf-mapper .
docker run -p 8000:8000 --env-file .env pdf-mapper

AWS Lambda

See deployment/aws/ for Lambda deployment scripts.

Azure Functions

See deployment/azure/ for Azure deployment scripts.

GCP Cloud Functions

See deployment/gcp/ for GCP deployment scripts.


🔗 Integration with SDK

Once the API server is running, install the SDK:

cd ../../sdks/python
pip install -e .

# Use CLI
pdf-autofiller --api-url http://localhost:8000 extract input.pdf

# Or Python
from pdf_autofiller import PDFMapperClient
client = PDFMapperClient("http://localhost:8000")
result = client.extract("input.pdf", 1, 100)

📚 Documentation


🔍 Troubleshooting

Module 'boto3' not found

# In config.ini, set:
[general]
rag_api_url = 
# Leave empty to disable RAG

API key errors

# Make sure .env has your key:
OPENAI_API_KEY=sk-your-actual-key-here

Import errors

# Install dependencies:
pip install -r requirements.txt

Server won't start

# Install API dependencies:
pip install -r requirements-api.txt

⚙️ Environment Variables

Key environment variables (set in .env):

Variable Required Description
CLOUD_PROVIDER ✅ local, aws, azure, or gcp
OPENAI_API_KEY ✅ OpenAI API key
ANTHROPIC_API_KEY 🔷 Claude/Anthropic key (if using Claude)
AWS_ACCESS_KEY_ID 🔷 AWS credentials (if using AWS)
AWS_SECRET_ACCESS_KEY 🔷 AWS credentials (if using AWS)
AZURE_STORAGE_CONNECTION_STRING 🔷 Azure credentials (if using Azure)
API_KEY ✅ (API server) Shared secret clients send as X-API-Key
MAPPER_ALLOW_INSECURE_NO_AUTH ⬜ true to explicitly run the API server without auth (local dev only)
MAPPER_CORS_ALLOWED_ORIGINS ⬜ Comma-separated allowed origins for the API server

📝 License

See LICENSE file in project root.


🤝 Contributing

See CONTRIBUTING.md for guidelines.


Quick Command Reference

# Setup
cp .env.example .env
cp config.ini.example config.ini
pip install -r requirements.txt requirements-api.txt

# Run server
python api_server.py

# Test
curl http://localhost:8000/health
pytest

# Install SDK (for client usage)
cd ../../sdks/python && pip install -e .

Metadata

Release files for pdf-autofillr-mapper 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdf-autofillr-mapper 1.0.11
File Size Uploaded
pdf_autofillr_mapper-1.0.11.tar.gz 15.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdf-autofillr-mapper 1.0.11
File Interpreter ABI Platform
pdf_autofillr_mapper-1.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 MB

Release files / pdf_autofillr_mapper-1.0.11.tar.gz

Download URL pdf_autofillr_mapper-1.0.11.tar.gz
Size 15.5 MB
Tags Source
SHA-256 checksum
How to use checksums
50c40820aa833a986367bb4c639f637262f31cbe0596a1891b632e39d3b3f4e2
BLAKE2b-256 checksum
How to use checksums
20d4b971e65aa4ca15dc04e0b9b5a3ffbe32271d04e785bd2f94e467298eca0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / pdf_autofillr_mapper-1.0.11-py3-none-any.whl

Download URL pdf_autofillr_mapper-1.0.11-py3-none-any.whl
Size 15.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0e93839df6feec6bb65397c691ce156091f685128f8e6dca8cb0f36483c848b2
BLAKE2b-256 checksum
How to use checksums
85e5c201b7a5d6b71fae8c5b57b209ea05a9c6e9046cacea7a9c4e36ab638e85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.0.11 This release

2 release files

1.0.10

1 release file

1.0.9

1 release file

1.0.8

2 release files

1.0.7

1 release file

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page