/py-fsrs

Python Package for FSRS

Primary LanguagePythonMIT LicenseMIT

Open Spaced Repetition logo

🧠🔄 Build your own Spaced Repetition System in Python 🧠🔄


Py-FSRS is a python package that allows developers to easily create their own spaced repetition system using the Free Spaced Repetition Scheduler algorithm.


Installation

You can install the fsrs python package from PyPI using pip:

pip install fsrs

Quickstart

Import and initialize the FSRS scheduler

from fsrs import *

f = FSRS()

Create a new Card object

# all new cards are 'due' immediately upon creation
card_object = Card()

Review the card

scheduling_cards = f.repeat(card_object)

Choose a rating and update the card object

# you can choose one of the four possible ratings
"""
Rating.Again # forget; incorrect response
Rating.Hard # recall; correct response recalled with serious difficulty
Rating.Good # recall; correct response after a hesitation
Rating.Easy # recall; perfect response
"""

card_rating = Rating.Good

card_object = scheduling_cards[card_rating].card

See when the card is due next

from datetime import datetime, timezone

due = card_object.due

# how much time between when the card is due and now
time_delta = due - datetime.now(timezone.utc)

print(f"Card due: at {repr(due)}")
print(f"Card due in {time_delta.seconds} seconds")

"""
> Card due: at datetime.datetime(2024, 7, 6, 20, 6, 39, 147417, tzinfo=datetime.timezone.utc)
> Card due in: 599 seconds
"""

Reference

Card objects have one of four possible states

State.New # Never been studied
State.Learning # Been studied for the first time recently
State.Review # Graduate from learning state
State.Relearning # Forgotten in review state

There are four possible ratings when reviewing a card object:

Rating.Again # forget; incorrect response
Rating.Hard # recall; correct response recalled with serious difficulty
Rating.Good # recall; correct response after a hesitation
Rating.Easy # recall; perfect response

Get the review log for a given rating

review_log = scheduling_cards[card_rating].review_log

Get the schdeduled days after rating a card

scheduled_days = card_object.scheduled_days

License

Distributed under the MIT License. See LICENSE for more information.