api reference.md - himent12/FlashGenie GitHub Wiki
Complete technical documentation for FlashGenie's classes, methods, and interfaces. This reference provides comprehensive coverage of the public API for developers building integrations, extensions, or contributing to the core codebase.
FlashGenie's API is organized into several key modules:
- Core Classes: Fundamental flashcard and deck management
- Smart Features: Intelligent learning algorithms
- Data Management: Storage and persistence
- User Interface: CLI and interaction components
- Utilities: Helper functions and tools
The fundamental unit of learning in FlashGenie.
from flashgenie.core.flashcard import Flashcard
Flashcard(
question: str,
answer: str,
tags: Optional[List[str]] = None,
difficulty: float = 1.0,
metadata: Optional[Dict[str, Any]] = None
)
Parameters:
-
question
(str): The question text -
answer
(str): The answer text -
tags
(List[str], optional): List of tags for categorization -
difficulty
(float, optional): Difficulty level (0.1-5.0), defaults to 1.0 -
metadata
(Dict[str, Any], optional): Additional metadata
Property | Type | Description |
---|---|---|
id |
str | Unique identifier |
question |
str | Question text |
answer |
str | Answer text |
tags |
List[str] | Associated tags |
difficulty |
float | Current difficulty level |
created_at |
datetime | Creation timestamp |
updated_at |
datetime | Last update timestamp |
review_count |
int | Number of times reviewed |
correct_count |
int | Number of correct answers |
last_reviewed |
datetime | Last review timestamp |
Add a tag to the flashcard.
Remove a tag from the flashcard. Returns True if tag was found and removed.
Update the difficulty level (clamped between 0.1 and 5.0).
Record a review attempt and update statistics.
Calculate the success rate as a percentage.
Convert flashcard to dictionary representation.
Create flashcard from dictionary (class method).
Container for managing collections of flashcards.
from flashgenie.core.deck import Deck
Deck(
name: str,
description: str = "",
flashcards: Optional[List[Flashcard]] = None,
metadata: Optional[Dict[str, Any]] = None
)
Property | Type | Description |
---|---|---|
id |
str | Unique identifier |
name |
str | Deck name |
description |
str | Deck description |
flashcards |
List[Flashcard] | List of flashcards |
created_at |
datetime | Creation timestamp |
updated_at |
datetime | Last update timestamp |
total_cards |
int | Total number of cards |
tags |
Set[str] | All unique tags in deck |
Add a flashcard to the deck.
Remove a flashcard by ID. Returns True if found and removed.
Retrieve a flashcard by ID.
Get all cards with a specific tag.
Get cards within a difficulty range.
Randomly shuffle the order of flashcards.
Get comprehensive deck statistics.
Manages quiz sessions and intelligent question selection.
from flashgenie.core.quiz_engine import QuizEngine, QuizSession
QuizEngine(
difficulty_analyzer: Optional[DifficultyAnalyzer] = None,
spaced_repetition: Optional[SpacedRepetitionAlgorithm] = None
)
Start a new quiz session.
Resume a previously saved session.
Represents an active quiz session.
Property | Type | Description |
---|---|---|
session_id |
str | Unique session identifier |
deck |
Deck | Associated deck |
current_card |
Optional[Flashcard] | Current flashcard |
score |
int | Current score |
total_questions |
int | Total questions answered |
correct_answers |
int | Number of correct answers |
start_time |
datetime | Session start time |
Get the next card based on intelligent selection.
Submit an answer and get correctness feedback.
Skip the current card.
End the session and return summary statistics.
Analyzes performance and adjusts card difficulty intelligently.
from flashgenie.core.difficulty_analyzer import DifficultyAnalyzer
Analyze performance metrics for a card.
Suggest difficulty adjustment based on performance.
Update card difficulty based on analysis.
Implements the SM-2 spaced repetition algorithm.
from flashgenie.core.spaced_repetition import SpacedRepetitionAlgorithm
Calculate when a card should next be reviewed.
Update the card's review schedule.
Handles persistence and data management.
from flashgenie.data.storage import DataStorage
Save a deck to persistent storage.
Load a deck from storage.
List all available decks.
Delete a deck from storage.
Create a backup of all data.
Restore data from a backup.
from flashgenie.data.importers.csv_importer import CSVImporter
Import flashcards from CSV file.
from flashgenie.data.importers.txt_importer import TXTImporter
Import flashcards from text file.
from flashgenie.data.exporters.csv_exporter import CSVExporter
Export deck to CSV format.
from flashgenie.data.exporters.json_exporter import JSONExporter
Export deck to JSON format.
from flashgenie import Flashcard, Deck, QuizEngine, DifficultyAnalyzer
# Create flashcards
card1 = Flashcard("What is Python?", "A programming language")
card2 = Flashcard("What is ML?", "Machine Learning")
# Create deck
deck = Deck("Programming Basics", flashcards=[card1, card2])
# Initialize quiz engine
analyzer = DifficultyAnalyzer()
quiz_engine = QuizEngine(analyzer)
# Start quiz session
session = quiz_engine.start_session(deck)
# Quiz loop
while session.has_more_cards():
card = session.get_next_card()
print(f"Question: {card.question}")
user_answer = input("Your answer: ")
is_correct = session.submit_answer(user_answer)
print("Correct!" if is_correct else f"Wrong. Answer: {card.answer}")
# Get session results
results = session.end_session()
print(f"Score: {results['score']}/{results['total']}")
from flashgenie import (
Deck, QuizEngine, DifficultyAnalyzer,
TagManager, SmartCollectionManager
)
# Create deck with tagged cards
deck = Deck("Advanced Topics")
deck.add_card(Flashcard("Define polymorphism", "...", tags=["OOP", "concepts"]))
deck.add_card(Flashcard("Explain inheritance", "...", tags=["OOP", "basics"]))
# Initialize smart features
tag_manager = TagManager()
collection_manager = SmartCollectionManager()
analyzer = DifficultyAnalyzer()
# Auto-categorize cards
tag_manager.auto_tag_deck(deck)
# Create smart collections
collection_manager.create_collection("Struggling Cards", {
"difficulty_min": 3.0,
"success_rate_max": 0.6
})
# Use smart collections
struggling_cards = collection_manager.get_collection("Struggling Cards")
cards = collection_manager.get_collection_cards(struggling_cards, deck)
print(f"Found {len(cards)} struggling cards")
from flashgenie.data.storage import DataStorage
from flashgenie.data.importers.csv_importer import CSVImporter
# Initialize storage
storage = DataStorage()
# Import from CSV
importer = CSVImporter()
cards = importer.import_from_file("my_cards.csv")
# Create and save deck
deck = Deck("Imported Deck", flashcards=cards)
storage.save_deck(deck)
# List all decks
decks = storage.list_decks()
for deck_info in decks:
print(f"Deck: {deck_info['name']} ({deck_info['card_count']} cards)")
Variable | Description | Default |
---|---|---|
FLASHGENIE_DATA_DIR |
Data directory path | ./data |
FLASHGENIE_LOG_LEVEL |
Logging level | INFO |
FLASHGENIE_CONFIG_FILE |
Config file path | ./config.json |
{
"spaced_repetition": {
"initial_interval": 1,
"easy_factor": 2.5,
"minimum_factor": 1.3
},
"quiz": {
"max_questions_per_session": 50,
"case_sensitive": false
},
"ui": {
"use_colors": true,
"clear_screen": true
}
}
from flashgenie.utils.exceptions import (
FlashGenieError,
DeckNotFoundError,
CardNotFoundError,
ImportError,
ExportError
)
Base exception for all FlashGenie errors.
Raised when a requested deck cannot be found.
Raised when a requested card cannot be found.
Raised when import operations fail.
Raised when export operations fail.
FlashGenie is designed for extensibility. Key extension points include:
from flashgenie.core.difficulty_analyzer import DifficultyAnalyzer
class MyCustomAnalyzer(DifficultyAnalyzer):
def analyze_performance(self, card, responses):
# Your custom analysis logic
return performance_metrics
def suggest_difficulty_adjustment(self, performance):
# Your custom adjustment logic
return difficulty_change
from flashgenie.data.importers.base_importer import BaseImporter
class MyCustomImporter(BaseImporter):
def import_from_file(self, file_path, config=None):
# Your custom import logic
return flashcards
from flashgenie.data.exporters.base_exporter import BaseExporter
class MyCustomExporter(BaseExporter):
def export_deck(self, deck, file_path):
# Your custom export logic
return success
- Decks are loaded entirely into memory
- Large decks (>10,000 cards) may impact performance
- Consider pagination for very large datasets
- Data is stored in JSON format by default
- File I/O operations are synchronous
- Consider async operations for large datasets
- Use smart collections to filter large decks
- Implement custom algorithms for specific use cases
- Cache frequently accessed data
This API reference is automatically updated with each release. For the latest version, see the GitHub repository.