A FastAPI-based web application that automatically generates flashcards from Notion pages with optional AI-powered summarization using chatbots like Groq and Mistral AI.
- Notion Integration: Extract content directly from Notion pages
- AI Summarization: Optional AI-powered summarization using Groq or Mistral
- Real-time Progress: WebSocket-based real-time progress tracking
- Rate Limiting: Built-in rate limiting to prevent API abuse
- Task History: Keep track of all flashcard generation tasks
- Error Handling: Comprehensive error handling and reporting
- CSV Export: Export flashcards in CSV format compatible with popular flashcard apps
- Python 3.12+
- Redis (for development)
- Redis Cluster (for production)
- Notion API Key
- Groq API Key (optional)
- Mistral API Key (optional)
- Clone the repository:
git clone <repository-url>
cd notion2anki
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements/base.txt -r requirements/api.txt
- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
Required environment variables:
NOTION_API_KEY=your_notion_api_key
GROQ_API_KEY=your_groq_api_key
MISTRAL_API_KEY=your_mistral_api_key
- Start Redis:
docker-compose up -d redis
- Run the development server:
uvicorn src.api.main:app --reload --ws wsproto --host 0.0.0.0 --port 8000
Run tests using pytest:
make test # Run tests
make test-cov # Run tests with coverage
make test-html # Generate coverage HTML report
POST /generate-flashcards/
: Start flashcard generationGET /task-status/{task_id}
: Get generation task statusGET /generation-history
: Get history of generation tasksGET /preview-flashcards/{task_id}
: Preview generated flashcardsGET /download/{task_id}
: Download flashcards as CSV
WS /ws/{task_id}
: Real-time task progress updates
GET /health
: System health status
- Set up Redis Cluster:
docker compose -f docker-compose.prod.yml up -d
-
Configure environment variables for production.
-
Run with production server:
uvicorn src.api.main:app --ws wsproto --host 0.0.0.0 --port 8000
The application implements a comprehensive error handling system:
- Domain-specific exceptions for better error context
- Proper error logging and reporting
- Rate limiting error handling
- WebSocket error management
pre-commit
: Code formatting and linting hooksblack
: Code formattingisort
: Import sortingpytest
: Testing framework
make test
: Run testsmake test-cov
: Run tests with coverage reportmake test-html
: Generate HTML coverage reportmake clean
: Clean temporary files
- Install development dependencies:
pip install -r requirements/dev.txt
- Install pre-commit hooks:
pre-commit install
- Follow the existing code style and add tests for new features.
- FastAPI for the web framework
- Notion API for content extraction
- Groq and Mistral for AI summarization