ReceiptIQ API is a FastAPI-based service that provides intelligent receipt processing using AI-powered data extraction and interpretation. The service processes receipt images and PDFs using OCR (Optical Character Recognition) and then uses AI to intelligently structure and interpret the data according to user-defined schemas.
- AI-Powered Data Extraction: Uses OpenAI GPT models to intelligently extract structured data from receipts
- Multi-Format Support: Processes images (JPEG, PNG, GIF) and PDF documents
- Custom Schema Definition: Users can define custom fields and data structures for extraction
- Project Management: Organize receipts into projects with custom field schemas
- Subscription Management: Built-in subscription system with Paystack integration
- User Authentication: JWT-based authentication with role-based permissions
- Data Export: Export extracted data as JSON or CSV
- File Storage: AWS S3 integration for secure file storage
- PostgreSQL Database: Robust data storage with SQLAlchemy ORM
- Docker Support: Easy deployment with Docker Compose
- Docker and Docker Compose
- Python 3.11+ (for local development)
- PostgreSQL (included in Docker setup)
- OpenAI API key (for AI interpretation)
- AWS S3 credentials (for file storage)
- Paystack API key (for subscription payments)
- Resend API key (for email notifications)
- Clone the repository:
git clone <repository-url>
cd receiptiq_api- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env and add your API keys and configuration- Start the development environment using Docker Compose:
docker compose up --buildThe API will be available at http://localhost:9000
Once the server is running, you can access:
- Interactive API documentation:
http://localhost:9000/docs - Alternative API documentation:
http://localhost:9000/redoc
receiptiq_api/
├── api/ # API route handlers
│ ├── auth.py # Authentication endpoints
│ ├── projects.py # Project management
│ ├── fields.py # Schema field definitions
│ ├── receipts.py # Receipt upload and processing
│ ├── data.py # Data export and management
│ └── subscriptions.py # Subscription management
├── models/ # SQLAlchemy database models
├── schemas/ # Pydantic data validation schemas
├── utils/ # Utility functions and services
│ ├── extractor.py # AI-powered data extraction
│ ├── storage.py # File storage service
│ └── rate_limiter.py # Rate limiting
├── migrations/ # Database migrations
├── tests/ # Test suite
├── Dockerfile # Container configuration
├── compose.yml # Service orchestration
└── requirements.txt # Python dependencies
The following environment variables can be configured:
POSTGRES_USER: PostgreSQL usernamePOSTGRES_PASSWORD: PostgreSQL passwordPOSTGRES_DB: Database namePOSTGRES_HOST: Database hostPOSTGRES_PORT: Database portSECRET_KEY: JWT secret keyOPENAI_API_KEY: Your OpenAI API key for AI interpretationAWS_ACCESS_KEY_ID: AWS S3 access keyAWS_SECRET_ACCESS_KEY: AWS S3 secret keyAWS_REGION: AWS regionBUCKET_NAME: S3 bucket namePAYSTACK_SECRET_KEY: Paystack payment gateway keyRESEND_API_KEY: Email service API key
- User Registration: Users sign up and verify their email with OTP
- Project Creation: Users create projects and define custom field schemas
- Receipt Upload: Receipt images/PDFs are uploaded to projects
- AI Processing: The system uses OCR and AI to extract data:
- OCR extracts text from images using Tesseract
- PDF processing extracts text and coordinates
- AI (OpenAI GPT) interprets and structures data according to schema
- Data Storage: Extracted data is stored in PostgreSQL with coordinates
- Data Access: Structured data is available through API endpoints
- Export: Data can be exported as JSON or CSV
POST /api/v1/auth/signup: Register new userPOST /api/v1/auth/otp/get: Request OTP verificationPOST /api/v1/auth/otp/check: Verify OTP and get access tokenPOST /api/v1/auth/token: Login with email/passwordPOST /api/v1/auth/token/refresh: Refresh access tokenPOST /api/v1/auth/logout: Logout and revoke tokens
POST /api/v1/projects: Create a new projectGET /api/v1/projects: List all projectsGET /api/v1/projects/{project_id}: Get project detailsPUT /api/v1/projects/{project_id}: Update projectDELETE /api/v1/projects/{project_id}: Delete projectPOST /api/v1/projects/{project_id}/process: Process all pending receipts
POST /api/v1/projects/{project_id}/fields: Define a new fieldGET /api/v1/projects/{project_id}/fields: List all fields in a projectPUT /api/v1/projects/{project_id}/fields/{field_id}: Update fieldDELETE /api/v1/projects/{project_id}/fields/{field_id}: Delete fieldPOST /api/v1/projects/{project_id}/fields/{field_id}/add_child: Add child field
POST /api/v1/projects/{project_id}/receipts: Upload and process a receiptGET /api/v1/projects/{project_id}/receipts: List all processed receiptsGET /api/v1/projects/{project_id}/receipts/{receipt_id}: Get receipt detailsPUT /api/v1/projects/{project_id}/receipts/{receipt_id}: Update receipt status
GET /api/v1/projects/{project_id}/data: Get extracted data as JSONGET /api/v1/projects/{project_id}/data/csv: Export data as CSVPUT /api/v1/projects/{project_id}/data/{data_value_id}: Update data value
GET /api/v1/subscriptions/plans: List subscription plansPOST /api/v1/subscriptions/payments/start: Start payment processPOST /api/v1/subscriptions/payments/webhook: Paystack webhook handler
The system supports various field types for schema definition:
string: Text valuesnumber: Numeric valuesboolean: True/false valuesdate: Date valuesobject: Nested object structuresarray: Array of values
- Make changes to the code
- The server will automatically reload due to the
--reloadflag - Test your changes using the API documentation interface
- Run tests:
pytest - Check code coverage:
pytest --cov
The project includes comprehensive tests:
- Unit tests for models and utilities
- Integration tests for API endpoints
- Database tests with PostgreSQL
- S3 storage mocking with moto
Run tests with:
pytest- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
[Add your license information here]