A FastAPI microservice for merging PDFs from S3 presigned URLs. The service supports both staging and production environments and can handle both PDF and image files.
- Merge multiple PDFs into a single document
- Support for both PDF and image files
- Environment-specific endpoints (staging/production)
- S3 integration for file storage
- Comprehensive logging
- Docker support
- Swagger documentation
- Python 3.11+
- Docker (for containerized deployment)
- AWS credentials with S3 access
- Clone the repository:
git clone <repository-url>
cd pdf-merge-service- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create
.envfile with required environment variables:
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=your_region
STAGING_BUCKET_NAME=your_staging_bucket
PROD_BUCKET_NAME=your_prod_bucketStart the FastAPI server:
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Staging Endpoint:
POST /api/v1/staging/merge
- Production Endpoint:
POST /api/v1/prod/merge
Request body format:
{
"urls": ["presigned_url1", "presigned_url2", ...],
"lead_id": "unique_lead_id"
}- Build the Docker image:
docker build -t pdf-merge-service .- Run the container:
docker run -p 8000:8000 --env-file .env pdf-merge-serviceRun the test script:
python test_merge.pypdf-merge-service/
├── app/
│ ├── api/
│ │ └── endpoints.py
│ │ └── services/
│ │ └── pdf_service.py
│ │ └── utils/
│ │ └── logger.py
│ │ └── config.py
│ └── main.py
├── tests/
│ └── test_pdf_merge.py
├── .env
├── .gitignore
├── Dockerfile
├── README.md
└── requirements.txt
- FastAPI: Web framework
- Uvicorn: ASGI server
- PyPDF2: PDF manipulation
- Boto3: AWS SDK
- Pillow: Image processing
- ReportLab: PDF generation
- Python-dotenv: Environment management
- Pydantic: Data validation
Logs are stored in the logs directory with separate files for staging and production environments.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
[Your License]