Skip to main content

Anki SM-2 based spaced repetition scheduler

Project description

Open Spaced Repetition logo

Anki SM-2

🌟 Anki's SM-2-based spaced repetition algorithm 🌟


Python package implementing Anki's SM-2-based algorithm for spaced repetition scheduling.

Installation

You can install the anki-sm-2 python package from PyPI using pip:

pip install anki-sm-2

Quickstart

Import and initialize the Anki SM-2 Scheduler

from anki_sm_2 import AnkiSM2Scheduler, Card, Rating

scheduler = AnkiSM2Scheduler()

Create a new Card object

card = Card()

Choose a rating and review the card

"""
Rating.Again # (==0) forgot the card
Rating.Hard # (==1) remembered the card, but with serious difficulty
Rating.Good # (==2) remembered the card after a hesitation
Rating.Easy # (==3) remembered the card easily
"""

rating = Rating.Good

card, review_log = scheduler.review_card(card, rating)

print(f"Card rated {review_log.rating} at {review_log.review_datetime}")
# > Card rated 3 at 2024-10-31 01:36:57.080934+00:00

See when the card is due next

from datetime import datetime, timezone

due = card.due

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

print(f"Card due: at {due}")
print(f"Card due in {time_delta.seconds / 60} minutes")
# > Card due: at 2024-10-31 01:46:57.080934+00:00
# > Card due in 9.983333333333333 minutes

Usage

Timezone

Anki SM-2 uses UTC time only. You can still specify custom datetimes, but they must be UTC.

from anki_sm_2 import AnkiSM2Scheduler, Card, Rating, ReviewLog
from datetime import datetime, timezone

scheduler = AnkiSM2Scheduler()

# create a new card on Jan. 1, 2024
card = Card(created_at=datetime(2024, 1, 1, 0, 0, 0, 0, timezone.utc)) # right
#card = Card(created_at=datetime(2024, 1, 1, 0, 0, 0, 0)) # wrong

# review the card on Jan. 2, 2024
card, review_log = scheduler.review_card(card=card, rating=Rating.Good, review_datetime=datetime(2024, 1, 2, 0, 0, 0, 0, timezone.utc)) # right
#card, review_log = scheduler.review_card(card=card, rating=Rating.Good, review_datetime=datetime(2024, 1, 2, 0, 0, 0, 0)) # wrong

Serialization

Card and ReviewLog objects are json-serializable via their to_dict and from_dict methods for easy database storage:

# serialize before storage
card_dict = card.to_dict()
review_log_dict = review_log.to_dict()

# deserialize from dict
card = Card.from_dict(card_dict)
review_log = ReviewLog.from_dict(review_log_dict)

Versioning

This python package is currently unstable and adheres to the following versioning scheme:

  • Minor version will increase when a backward-incompatible change is introduced.
  • Patch version will increase when a bug is fixed, a new feature is added or when anything else backward compatible warrants a new release.

Once this package is considered stable, the Major version will be bumped to 1.0.0 and will follow semver.

Contribute

Checkout CONTRIBUTING to help improve Anki SM-2!

Official implementation

You can find the code for Anki's official Rust-based scheduler here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anki_sm_2-0.1.1.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

anki_sm_2-0.1.1-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file anki_sm_2-0.1.1.tar.gz.

File metadata

  • Download URL: anki_sm_2-0.1.1.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for anki_sm_2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cefd7e814921e7ad11f01a848d8eaaf26ba5e925faa1056d694cab70be6318e6
MD5 9b07787b80d2402e2c23b198062009cc
BLAKE2b-256 7636aaf1805c0b77687c6153a888b9cfaac9101c6ef15bede3a11237980f3a9d

See more details on using hashes here.

File details

Details for the file anki_sm_2-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: anki_sm_2-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for anki_sm_2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d08d082a2fac7c3fe92a170343686782dcc2f7af708492222461a686a677ed7
MD5 5fda55cef7d8babb56601480f1d9a505
BLAKE2b-256 dad244ecd1fef2dc5eabe1123a9a71385de96099d30b38089612c64edb518460

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page